Search Results

Search found 1848 results on 74 pages for 'printf'.

Page 53/74 | < Previous Page | 49 50 51 52 53 54 55 56 57 58 59 60  | Next Page >

  • How can I work around the fact that in C++, sin(3.14159265) is not 0?

    - by Adam Doyle
    In C++, const double Pi = 3.14159265; cout << sin(Pi); // displays: 3.58979e-009 it SHOULD display the number zero I understand this is because Pi is being approximated, but is there any way I can have a value of Pi hardcoded into my program that will return 0 for sin(Pi)? (a different constant maybe?) In case you're wondering what I'm trying to do: I'm converting polar to rectangular, and while there are some printf() tricks I can do to print it as "0.00", it still doesn't consistently return decent values (in some cases I get "-0.00") The lines that require sin and cosine are: x = r*sin(theta); y = r*cos(theta); BTW: My Rectangular - Polar is working fine... it's just the Polar - Rectangular Thanks! edit: I'm looking for a workaround so that I can print sin(some multiple of Pi) as a nice round number to the console (ideally without a thousand if-statements)

    Read the article

  • http response to GET request - working in FF not Chromium

    - by Tyler
    For fun I'm trying to write a very simple server in C. When I send this response to Firefox it prints out the body "hello, world" but with Chromium it gives me a Error 100 (net::ERR_CONNECTION_CLOSED): Unknown error. This, I believe, is the relevant code: char *response = "HTTP/1.0 200 OK\r\nVary: Accept-Encoding, Accept-Language\r\nConnection: Close\r\nContent-Type: text/plain\r\nContent-Length:20\r\n\r\nhello, world"; if(send(new_fd, response, strlen(response), 0) == strlen(response)) { printf("sent\n"); }; close(new_fd); What am I missing? Thanks!

    Read the article

  • A question for retrieve minix os version

    - by majnun
    Hi guys i'm having a project for the university in which (above others ) i have to get the minix os version from kernell call.I'm not a very experienced programmer so this is what i have come to (with some help ) int main (int argc, char *argv[] ) { char M3ca1[23]; message ml; m.m_u.m_m1.m3ca1= OS_VERSION; char temp=_syscall(MM,69,&m); printf("the os version is %c\n",temp); return 0; } and i get multiple errors.IF you have any ideas it would be greatly appreciated.

    Read the article

  • Using Delphi or FFMpeg to create a movie from image sequence

    - by Hein du Plessis
    Hi all My Delphi app has created a squence called frame_001.png to frame_100.png. I need that to be compiled into a movie clip. I think perhaps the easiest is to call ffmpeg from the command line, according to their documentation: For creating a video from many images: ffmpeg -f image2 -i foo-%03d.jpeg -r 12 -s WxH foo.avi The syntax foo-%03d.jpeg specifies to use a decimal number composed of three digits padded with zeroes to express the sequence number. It is the same syntax supported by the C printf function, but only formats accepting a normal integer are suitable. From: http://ffmpeg.org/ffmpeg-doc.html#SEC5 However my files are (lossless) png format, so I have to convert using imagemagick first. My command line is now: ffmpeg.exe -f image2 -i c:\temp\wentelreader\frame_%05d.jpg -r 12 foo.avi But then I get the error: [image2 @ 0x133a7d0]Could not find codec parameters (Video: mjpeg) c:\temp\wentelreader\Frame_C:\VID2EVA\Tools\Mencoder\wentel.bat5d.jpg: could not find codec parameters What am I doing wrong? Alternatively can this be done easily with Delphi?

    Read the article

  • Why am I not getting the expected results with fread() in C?

    - by mauvehead
    Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i; char bytes[512]; fp = fopen("myFile","r"); for(i = 0;i <= 512;i++) { fread(&bytes, sizeof(bytes), 1, fp); printf("bytes[%d]: %x\n", i, bytes[i]); } } Here is the expected output $ hexdump myFile 0000000 aa55 aa55 0060 0000 0a17 0000 b1a5 a2ea 0000010 0000 0000 614c 7563 616e 0000 0000 0000 0000020 0000 0000 0a68 0000 1001 421e 0000 0000 0000030 f6a0 487d ffff ffff 0040 0000 002f 0000 But here is what I see from my program bytes[0]: 55 bytes[1]: 8 bytes[2]: ffffffc8 bytes[3]: ffffffdd bytes[4]: 22 bytes[5]: ffffffc8 bytes[6]: ffffff91 bytes[7]: 63 bytes[8]: ffffff82 My obvious guess is that I'm either addressing something incorrectly and receiving the wrong data back or I am printing it incorrectly and viewing it the wrong way.

    Read the article

  • Using stack defined in C++ stl

    - by cambr
    #include <stack> using namespace std; int main() { stack<int> s; int i; for (i = 0; i <= 10; i++) { s.push(i); } for (i = 0; i <= 10; i++) { printf("%d", s.pop()); } } Whats wrong with the code above? Error: In function `int main()': aggregate value used where an integer was expected

    Read the article

  • long integer problem

    - by hopefulLLl
    hello friends,, m a beginner at c language.. m using turbo c ++ compiler 16 bit. nw the max answer obtained by me is aaround 32000.. nw if i want a number larger that that then i use long int.. if i execute the following programme.. #include <stdio.h> void main() { long int x; x=40000; printf("%d", x); } then i get error that constant value is long in function main().. kindly tell me how to get an answer more that 32000 by getting rid of this error! thnx..

    Read the article

  • Decoding equivalent assembly code of C code...

    - by puffadder
    Hi All, Wanting to see the output of the compiler (in assembly) for some C code, I wrote a simple program in C and generated its assembly file using gcc. The code is this: #include <stdio.h> int main() { int i = 0; if ( i == 0 ) { printf("testing\n"); } return 0; } The generated assembly for it is here (only the main function): _main: pushl %ebpz movl %esp, %ebp subl $24, %esp andl $-16, %esp movl $0, %eax addl $15, %eax addl $15, %eax shrl $4, %eax sall $4, %eax movl %eax, -8(%ebp) movl -8(%ebp), %eax call __alloca call ___main movl $0, -4(%ebp) cmpl $0, -4(%ebp) jne L2 movl $LC0, (%esp) call _printf L2: movl $0, %eax leave ret I am at an absolute loss to correlate the C code and assembly code. All that the code has to do is store 0 in a register and compare it with a constant 0 and take suitable action. But what is going on in the assembly ? Thanks in advance.

    Read the article

  • How do I redirect output from the Visual Studio debugger?

    - by jeatsy
    In Visual Studio 2008, I can specify a message to be printed when a breakpoint is hit (by right-clicking the breakpoint and choosing 'When Hit...'). When the program is run, these messages appear in the Output Window. I would like to know, is there any way to redirect them to a file? Specifying file.txt as a command argument to the program does not work: this redirects the program's output, but not the debugger's. (FWIW the behaviour I wish to achieve is to get the debugger to repeatedly print a variable's value to a file, rather than peppering my code with printf/cout statements.)

    Read the article

  • How to make this code compile?

    - by skydoor
    // File: foo.c static int var; void foo() { var++; } // end of file foo.c // File bar.c: static int var; void bar() { var++; } // end of file bar.c // file main.c static int var; void main() { foo(); bar(); printf("%d", var); } // end of file main.c Question: Will the above program compile ? If so what will be the result ? I tested the code and found it couldn't be compiled. I try to use extern in main.c to use the function foo() and bar() but it still couldn't be compiled.

    Read the article

  • NSBitmapImageRep data Format as application icon image??

    - by Joe
    i have a char* array of data that was in RGBA and then moved to ARGB Bottom line is the set application image looks totally messed up and i cant put my finger on why? //create a bitmap representation of the image data. //The data is expected to be unsigned char** NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes : (unsigned char**) &dest pixelsWide:width pixelsHigh:height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bitmapFormat:NSAlphaFirstBitmapFormat bytesPerRow: 0 bitsPerPixel:0 ]; NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)]; [image addRepresentation:bitmap]; if( image == NULL) { printf("image is null\n"); fflush(stdout); } [NSApp setApplicationIconImage :image]; What in these values is off? the image looks very multicolored and pixelated, with transparent parts/lines as well.

    Read the article

  • why does this code crash?

    - by ashish yadav
    why does this code crash? is using strcat illegal on character pointers? #include <stdio.h> #include <string.h> int main() { char *s1 = "Hello, "; char *s2 = "world!"; char *s3 = strcat(s1, s2); printf("%s",s3); return 0; } please give a proper way with referring to both array and pointers.

    Read the article

  • Why does this code read all ' ' for the anything after the 4th character?

    - by djs22
    #define fileSize 100000 int main(int argc, char *argv[]){ char *name=argv[1]; char ret[fileSize]; FILE *fl = fopen(name, "rb"); fseek(fl, 0, SEEK_END); long len = fileSize; fseek(fl, 0, SEEK_SET); //fread(ret, 1, len, fl); int i; *(ret+fileSize) = '\0'; for (i=0; i<fileSize; i++){ *(ret+i)=fgetc(fl); printf("byte : %s \n", ret); } fclose(fl); } In the above code, when I feed the name of a jpeg file, it reads anything after the 4th character as ' '...any ideas? Thanks!

    Read the article

  • Is there a better way than #if DebugMode for logging

    - by Daniel
    I'm making a c++ library thats going to be P/Invoked from c#, so i am unable to breakpoint/debug the c++ side of things. So i decided to add logging so i can see if anything goes wrong and where it happens. I add a #define DebugMode 1 in order to determine if i am to log or not. First of all i'm not very good at c++ but i know enough to get around. So my questions are: Is there a better way than wrapping #if DebugMode #endifs around every Log call? I could simply do that inside the method and just return if logging isn't disabled but won't that mean then all those logging strings will be in the assembly? How can i emulate what printf does with its "..." operator enabling me to pass something like Log("Variable x is {0}", x); Thanks!

    Read the article

  • What's an easy way to set up object communication in Obj-C?

    - by seaworthy
    I am trying to send a slider value from a controller object to a method of a model object. The later is implemented in the separate file and I have appropriate headers. I think the problem is that I am not sure how to instantiate the receiver in order to produce a working method for the controller. Here is the controller's method. -(IBAction)setValue:(id)slider {[Model setValue:[slider floatValue]];} @implementation Model -(void)setValue:(float)n{ printf("%f",n); } @end What I get is 'Model' may not respond to '+setValue' warning and no output in my console. Any insight is appreciated.

    Read the article

  • printing uid of a file on linux system

    - by neo730
    i am learning c programming. I am trying to make my own program similar to ls command but with less options.what i am doing is taking input directory/file name as argument and then gets all directory entry with dirent struct(if it is directory) . After it i use stat() to take all information of the file but here is my problem when i use write() to print these value its fine but when i want to print these with printf() i get warninng : format ‘%ld’ expects type ‘long int’, but argument 2 has type ‘__uid_t’. I don't know what should use at place of %ld and also for other special data types.

    Read the article

  • Problem with the program!

    - by hopefulLLl
    Can you tell me what is the problem with this function. Can you help me to find the sum of digits of a number? #include<stdio.h> #include<math.h> void main() { int a,i=0,j=10,k,n=0,m; scanf("%d",&a); while((a%j!=0)&&i>=0) { m=pow(10,(i+1)); k=a%m; n=(a-(k*m)-n)/(m/10)+n; j=m*10; i++; } n=n+(n/(m/10)); printf("%d",n); } I need to use just the while loop... or the for loop! when i run it it shows"resumable processor fault"..help!

    Read the article

  • External class-calling

    - by anonymous
    Hi guys i have a bit of a problem with a few classes, and i would be very grateful if someone can help me out. So i have: Already compiled executable (for whom i don't have the source) A class in that program that i want to call The program doesn't have export for the class, and that's my problem i don't have definition for this class, so is there a way to get a callback to this class? Example: In the compiled executable: foo::bar (example) { printf(example); } My app: CALLBACK(foo::bar, "this text must be passed as argument") Or in other words i want to call a class in other executable (without having its source) and pass arguments to its function.

    Read the article

  • Separating null byte separated UNICODE C string.

    - by Ramblingwood
    First off, this is NOT a duplicate of: http://stackoverflow.com/questions/1911053/turn-a-c-string-with-null-bytes-into-a-char-array , because the given answer doesn't work when the char *'s are Unicode. I think the problem is that because I am trying to use Unicode and thus wchar_t instead of char, the length of each character is different and thus, this doesn't work (it does in non-unicode): char *Buffer; // your null-separated strings char *Current; // Pointer to the current string // [...] for (Current = Buffer; *Current; Current += strlen(Current) + 1) printf("GetOpenFileName returned: %s\n", Current); Does anyone have a similar solution that works on Unicode strings? I have been banging my head on the this for over 4 hours now. C doesn't agree with me.

    Read the article

  • function prototype declarations

    - by sandy101
    I am practice the function in c and come across to the program .... #include<stdio.h> int main() { float a=15.5; char ch ='C'; printit(a,ch); return 0; } printit(a,ch) { printf("%f\n%c",a,ch); } I want to know that why the above program compile and not give the error as i understood so for is ... The function in c must be declared with the specific prototype (but this program does not contain the prototype) why the program give the output 'x'for the char variable ? can the function in c are capable of accepting the value without being declared about type in parameters like what has done in the function declaration ?

    Read the article

  • how does fgets internally works?

    - by Registered User
    Well it is a basic question but I seem confused enough. #include<stdio.h> int main() { char a[100]; printf("Enter a string\n"); scanf("%s",a); } Basically the above is what I want to achieve. If I enter a string James Bond then I want that to be stored in array a. But the problem is because of presence of a blank space in between only James word is stored. So how can I solve this one. UPDATE After the replies given below I understand fgets() would be a better choice. I want to know internal working of fgets as why is it able to store the string with space where as scanf is not able to do the same.

    Read the article

  • Transposing a matrix

    - by ZaZu
    Hello, I want to transpose a matrix, its a very easy task but its not working with me : int testtranspose(testing *test,testing *test2){ int i,j; (*test2).colsmat2=(*test).rowsmat1; (*test2).rowsmat2=(*test).colsmat1 for(i=0;i<(*test).rowsmat1;i++){ for(j=0;j<(*test).colsmat1;j++){ ((*test2).mat[i][j])=((*test).mat[i][j]); } printf("\n"); } } I thought this is the correct method of doing it, but apparently for a matrix such as : 1 2 3 4 5 6 7 8 I get : 1 2 0 0 3 4 0 0 What is the problem ? Please help, Thanks !

    Read the article

  • doubt in sizeof implementation

    - by aks
    Below is the program to find the size of a structure without using sizeof operator: struct MyStruct { int i; int j; }; int main() { struct MyStruct *p=0; int size = ((char*)(p+1))-((char*)p); printf("\nSIZE : [%d]\nSIZE : [%d]\n", size); return 0; } My doubt is: Why is typecasting to char * required? If I don't use the char* pointer, the output is 1 - WHY?

    Read the article

  • Removing trailing newline character from fgets() input

    - by sfactor
    i am trying to get some data from the user and send it to another function in gcc. the code is something like this. printf("Enter your Name: "); if(!(fgets(Name, sizeof Name, stdin) != NULL)) { fprintf(stderr, "Error reading Name.\n"); exit(1); } However, i find that it has an \n character in the end. so if i enter John it ends up sending John\n. so how do i remove that \n and send a proper string.

    Read the article

< Previous Page | 49 50 51 52 53 54 55 56 57 58 59 60  | Next Page >