c

sizeof float (3.0) vs (3.0f)

Hi, What is the difference between sizeof(3.0) and sizeof(3.0f) I was expecting both of them to give the same result (sizeof float)..but its different. In 32 bit machine,gcc compiler, sizeof(3.0f) =>4 sizeof(3.0) => 8 Why so? ...

Console app with Qt Creator on Windows : wait before closing the console

I'm running a very simple console app on Windows with Qt Creator. When launching it, the dos console is openned, my output is displayed, but then the app terminates and the console immediately closes. How can I make sure the console will stay open until the user presses a key ? ...

strcmp() and signed / unsigned chars...

I am confused by strcmp(), or rather, how it is defined by the standard. Consider comparing two strings where one contains characters outside the ASCII-7 range (0-127). The C standard defines: int strcmp(const char *s1, const char *s2); The strcmp function compares the string pointed to by s1 to the string pointed to by s2. ...

Why use Macros in C?

Possible Duplicate: What are C macros useful for? Every few months I get an itch to go learn some bit of C that my crap college programming education never covered. Today it's macros. My basic understanding of macros is they're a simple search and replace that happens on your code prior to it being compiled. I'm having troubl...

strange C macro syntax (#var)

What does the # symbol mean when used as a variable prefix in a #define macro? For example, #define my_setopt(x,y,z) _my_setopt(x, 0, config, #y, y, z) ...

C# Training Quizzes

Hello there, I have been programming 10 years, mostly in vba and vb.net but I know c# well enough to program what I normally do. I yesterday was applying for a Senior c# position and I did so poorly on the induction test its not funny :) I have always found that for me the best way to learn and recall is via question's and answers (mul...

Why fwrite libc function is faster than write syscall?

Okay, this is for a homework; although I'm not requesting any help on the programming side. It's already done :) After providing the same program which reads a random generated input file and echoes the same string it readed to an output. The only difference is that on one side I'm providing the read and write methods from linux syscals...

Initialize 2-D array of unknown size

I have a 2-D array of characters e.g. char aList[numStrings][maxLength]. ideally, during program execution I want to be able to modify the contents of aList i.e. add, amend or delete entries. Since aList will be subject to change, I don't want to have to recompile my program after every such change to modify aList. So I want to write aL...

Question regarding pointers in fscanf.

I am using C. I am having issues with using pointers for the fscanf function. When I try to do: int *x; /* ... */ fscanf(file, "%d", x[i]); My compiler gives me a warning saying "format argument is not a pointer" and the code just doesn't run (I get a message saying "Water.exe has stopped working"). If I replace x with *x, it just doe...

Using KLone for web development

Would anyone be kind enough to share about your experience using KLone in a web project? Mostly, in what context are you using it? Their home page mentions that: KLone is a fully-featured, multiplatform, web application development framework, targeted especially for embedded systems and appliances. However, to what extent if an...

Comlexity of algorithms - exercises

Hello. I'm learning for an exam in an introductory course to computer science, and i have a problem with the topic of complexity, both in "regular" algorithms and also in recursive algorithms (usually we get these questions written as C code). I was wondering if there're online examples somewhere in the internet and/or book that covers ...

free() errors (debugging with valgrind)?

I have these structs: typedef struct _Frag{ struct _Frag *next; char *seq; int x1; int length; }Frag; typedef struct _Fragment{ int type; Frag *frag_list; }Fragment; And then I created a array Fragment *fragments=malloc(1,sizeof(Fragment)); // or more fragments->frag_list=malloc(1,sizeof(Frag)); // or more Frag *...

How does this C code work?

I was looking at the following code I came across for printing a string in reverse order in C using recursion: void ReversePrint(char *str) { //line 1 if(*str) { //line 2 ReversePrint(str+1); //line 3 putchar(*str); //line 4 } } I am relatively new to C and am confused by line 2. *str fr...

Hebrew support in a C ncurses application

We have a C nurses based application (runs on most flavours of Unix, but we favour RHEL). We've got Unicode support in there, but now we have to provide a Hebrew version of the application. Does anyone know a process we could go through to convert the program? It mainly gets and stores data from Oracle, which can support Hebrew, so there...

Using C with inline assembler beginner problem

Hello! I am just testing and trying to learn how assembler works with C. So i was browsing around some tutorials and i found this: __asm { mov ax,0B800h //startaddress for the screen memory (in textmode) mov es,ax //add the startaddress to es xor di,di //reset di (start at the beginnin...

naming convention of temp local variables

What is the standard way to name a temp variable in the local function? let me give you an illustration of what I am doing. I get a pointer to a structure, so I want store one of its members locally to avoid a de-referenced, and then any modification assign back to the pointer. To be more concrete: struct Foo { double m_d; }; vo...

How prevent from dynamic relocation (rela.dyn)?

I am trying to run a simple program on an powerpc embedded system without any operating system. I am using GNU compiler-linker tools and PSIM as simulator. I've written my own very simple Linker Directive file. I've used a global variable in my static library and want to use that variable in my sample program. But while linking the samp...

C compiler flag to ignore sign

I am currently dealing with code purchased from a third party contractor. One struct has an unsigned char field while the function that they are passing that field to requires a signed char. The compiler does not like this, as it considers them to be mismatched types. However, it apparently compiles for that contractor. Some Googling has...

Accessing WINAPI methods within C

Hi I would like to access the DeleteFile WINAPI system call within my C Code. When checking the Windows File Management functions it outlines me just the C++ Syntax: C++ BOOL WINAPI DeleteFile( __in LPCTSTR lpFileName ); What I would like to know is how I can use this function within pure C code? I have never done anything with ...

Respond to only the first WM_KEYDOWN notification?

How can a Win32 application respond to only the first WM_KEYDOWN notification? The MSDN docs claim bit 30 "Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up." but bit 30 is always 0 in my WndProc. case WM_KEYDOWN: // ToDo - stop multiple notifications for ...