c

Preprocessor directive #ifndef for C/C++ code

In eclipse, whenever I create a new C++ class, or C header file, I get the following type of structure. Say I create header file example.h, I get this: /*Comments*/ #ifndef EXAMPLE_H_ #define EXAMPLE_H_ /* Place to put all of my definitions etc. */ #endif I think ifndef is saying that if EXAMPLE_H_ isn't defined, define it, which may...

Need Lex and Yacc program which does C syntax-checking

Anybody knows from where I can download a Lex and Yacc program(the source code) for complete syntax checking of a C program? Pls post the link as comment ...

Argument 'sample2' conceals a global declaration of the same symbol

Hello guys, I have a weird problem in C. I have a structure and I pointed sample to that structure : test sample; now in the code, I call that structure through a function : function is called something, so something(&sample) is used to point the structure in the function. Now I need to copy values of sample to sample2 .. So I want ...

show List of Roles in a dropdown box but except "Admin" role

hi, i am having a dropdown box showing list of roles, i used Roles.GetAllroles() for showin' all roles in dropdown box but i don't wanna show a role named "Admin" in the dropdown box. ...

What is the state of C99 support in major compilers / toolchains?

A response to a comment I made here made me stop and think: "I don't really know what the state of C99 support is." Wikipedia gives details for a few compilers, but I'm not familiar enough with C99 to know all the bits and pieces of the standard, so I'm looking for a gestalt overview answer to the question: What is the state of C99 sup...

Read and write struct in C

I have a struct: typedef struct student { char fname[30]; char sname[30]; char tname[30]; Faculty fac; int course; char group[10]; int room; int bad; } Student; I read it from the file: Database * dbOpen(char *fname) { FILE *fp = fopen(fname, "rb"); List ...

how const keyword works in c

Hi, I want to know about const internals in c and c++ . How compiler imposes constantness ? Can some one help me please. ...

How does the where clause in MySQL work ?

I have a doubt. Assume R and S are 2 relations with attributes A and B respectively . If I have a query Select * From R, S Where R.A = S.B Does this work like a double For Loop in say c or c++ For( i=0; i<n; i++) For( j=0; j<n; j++) if (i == j) //DO some work ...

How to use two parameters pointing to the same structure in one function ?

Hey guys, I have my code below that consits of a structure, a main, and a function. The function is supposed to display two parameters that have certain values, both of which point to the same structure. The problem I dont know how to add the SECOND parameter onto the following code : #include<stdio.h> #define first 500 #define sec 5...

Scan Numbers among letters in a Sentence

Hello, I have a pretty easy question. (using C) In a sentence such as In this document, there are 345 words and 6 figures How can I scan 345 and 6 while ignoring all that is in between ? I tried fscanf(FILE *pointer,"%d %d",&words,&figs); But it only gets the first value ... What am I doing wrong ? EDIT Im sorry I forgot to ment...

C: sprintf and recursion

In C, is it possible to use recursion within the sprintf function ? For some reason I get a segmentation fault when I do it: inline char *TreeNode_toString(const TreeNode *node) { char *out; if(TreeNode_isExternal(node)) // If the node has no children... { sprintf(out, "%s:%.2f", node->name, node->distance); } else // The...

gcov and switch statements

I'm running gcov over some C code with a switch statement. I've written test cases to cover every possible path through that switch statement, but it still reports a branch in the switch statement as not taken and less than 100% on the "Taken at least once" stat. Here's some sample code to demonstrate: #include "stdio.h" void foo(int ...

RE-Storing a NTFS Security Descriptor in C

Hello all, I'm trying to create a utility which exports a file's security descriptor, and re-assign it on demand. I've created a test sample, which uses GetSecurityInfo() with the DACL flag, and then try to re-assign the very same DACL with SetSecurityInfo(). Before applying SetSecurityInfo(), the descriptor's 'Control' is: 0xA004 , SE...

Simplest way to use isdigit and isalpha commands ?

Hello, Can anyone briefly explain how do these two commands work ? isdigit and isalpha .. Ofcourse I read online sources before asking the question, but unfortunately I tried them and didnt get them to work. What is the simplest way ? I know it gives back a value, so im assuming I can use it like this : if(isdigit(someinput)==1) r...

C Check Substring of a String C

I'm trying to check whether or not the second argument in my program is a substring of the first argument. The problem is that it only work if the substring starts with the same letter of the string. EDIT: It must be done in C, not C++. Sorry int main(int argc, char **argv){ if (argc != 3) { printf ("Usage: check <string o...

How can I output different shades of green to the terminal?

I'm currently using the following code to output text in green to the terminal: printf("%c[1;32mHello, world!\n", 27); However, I want more shades of green. What's the easiest way to accomplish this? ...

Calculating CPU frequency in C with RDTSC always returns 0

Hi, The following piece of code was given to us from our instructor so we could measure some algorithms performance: #include <stdio.h> #include <unistd.h> static unsigned cyc_hi = 0, cyc_lo = 0; static void access_counter(unsigned *hi, unsigned *lo) { asm("rdtsc; movl %%edx,%0; movl %%eax,%1" : "=r" (*hi), "=r" (*lo) : /...

[C] hide curl_easy_perform

How can I hide curl_easy_perform output (in a shell)? This is in regards to a C application. ...

Writing a VM - well formed bytecode?

Hi, I'm writing a virtual machine in C just for fun. Lame, I know, but luckily I'm on SO so hopefully no one will make fun :) I wrote a really quick'n'dirty VM that reads lines of (my own) ASM and does stuff. Right now, I only have 3 instructions: add, jmp, end. All is well and it's actually pretty cool being able to feed lines (doing i...

Designing an API with compile-time option to remove first parameter to most functions and use a global.

I'm trying to design a portable API in ANSI C89/ISO C90 to access a wireless networking device on a serial interface. The library will have multiple network layers, and various versions need to run on embedded devices as small as an 8-bit micro with 32K of code and 2K of data, on up to embedded devices with a megabyte or more of code an...