c

conversion to ‘size_t’ from ‘int’ may change the sign of the result - GCC , C

In my project I have turned on treat warnings as errors and compiling using the -pedantic and -ansi tags. I am using GCC compiler. In this project I have to use a third party source code which has got lot of warnings. Since I treat warnings as errors, I am having a tough time in fixing their code. Most of the warnings are about invalid...

How to change variable??

what should try() function should have to get the output as 11 from the below program? int main() { int x = 10; try(); printf("%d",x); return 0; } try() { /* how to change x here?? */ } ...

file operation write is not happening in new line

Hi following code sample seems to have some problem or either it has to do something with OS internals. #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> static void usage(); #define MONC_AM_CONF "/tmp/monc.c...

reading in a file and getting the string length

Hello, gcc 4.4.4 c89 I am using the following code to read in file using fgets. I just want to get the gender which could be either M or F. However, as the gender is always the last character in the string. I thought I could get the character by using strlen. However, for some reason I have to get the strlen and minus 2. I know that t...

How can I record system calls (including related parameters) of an application from the kernel?

Hi ,guys I want to record system calls (including parameters) invoked by an application from the kernel. Somebody told me I can hook all system calls or hook the sysenter, however, I don’t know how to do it. By the way, I have tried the strace utility, but it seemed that the strace provided me more system calls than what I expected. For ...

Perl and external programs

Hi, I have a Perl program and a C program. I want to run the Perl program and capture the return value of C program. To make it clear: C program (a.out) int main() { printf("100"); return 100; } Perl program: print `ls`; #OK print `a.out`; #No error but it does not print any output. Any ideas? Thanks. ...

Is there a tool to keep my C source files in order?

I have some C source files that are slowly expanding. I tend to keep the prototypes with documentation in the .h file in good order, grouped into relevant functions and types with #pragma mark. The code is written and documented in a way that requires reading the .h file alongside the .c file. I'd like the files to be ordered in a way th...

What does this compiler warning generated by `-pedantic` mean?

What does this GCC warning mean? cpfs.c:232:33: warning: ISO C99 requires rest arguments to be used The relevant lines are: __attribute__((format(printf, 2, 3))) static void cpfs_log(log_t level, char const *fmt, ...); #define log_debug(fmt, ...) cpfs_log(DEBUG, fmt, ##__VA_ARGS__) log_debug("Resetting bitmap"); The last line bei...

Unable to find bug in this C program.

I'm unable to find bug in this C program. #include <stdio.h> int main() { struct book { char name ; float price ; int pages ; } ; struct book b[3] ; int i ; int k; for ( i = 0 ; i <= 2 ; i++ ) { printf ( "\nEnter name, price and pages: " ) ; k = scanf ( "%c %f...

How to disable GCC warnings for a few lines of code

In Visual C++, it's possible to use #pragma warning (disable: ...). Also I found that in GCC you can override per file compiler flags. How can I do this for "next line", or with push/pop semantics around areas of code using GCC? ...

How to understand the "NTSTATUS", "NT_SUCCESS" typedef in windows ddk?

Two questions: 1. In "ntdef.h" the NTSTATUS is defined as follow: typedef __success(return >= 0) LONG NTSTATUS; what the hell is the "__success(return >= 0)"? 2. In "ntstatus.h", STATUS_SUCCESS is defined to 0. #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) // ntsubauth But the NT_SUCCESS macro in "ntdef.h" is: #define NT_SU...

programmatically create a pad sound

Okay this one may be a bit out from left field, but I'm going to try anyways. A pad is a sort of ambient electronic sound that kind of 'hums'. Something like this . How can I produce this in code? Using either Processing, OpenFrameworks, C, Objective-C or C++. Keep in mind I haven't been programming for that long. I will be very imp...

Segmentation fault when returning a struct

I am trying to do a pretty simple thing - it is reading a file and then turning it into a char** splitting it into lines. However when I return a struct containing the char** and size i get Segmentation fault. I read here: http://stackoverflow.com/questions/3047163/c-segmentation-fault-before-during-return-statement that it's probably "m...

sleep function in Windows, using C

I need to sleep my program in Windows. What header file has the sleep function? ...

Avoiding the main (entry point) in a C program

Is it possible to avoid the entry point (main) in a C program. In the below code, is it possible to invoke the func() call without calling via main() in the below program ? If Yes, how to do it and when would it be required and why is such a provision given ? int func(void) { printf("This is func \n"); return 0; } int main(vo...

C to delphi converting

Hi, can somebody tell me where I am making mistake in the converting: C: typedef struct _REGISTRY_EVENT { REG_NOTIFY_CLASS eventType; TIME_FIELDS time; HANDLE processId; ULONG dataType; ULONG dataLengthB; ULONG registryPathLengthB; /* Contains path and optionally data */ UCHAR registryData[]; } REGISTRY_...

C - PJLIB why not working?

I follow this PJLIB ( https://trac.pjsip.org/repos/wiki/Getting-Started/Autoconf ). But i cant get this up yet, always its giving undefined reference, can anyone please have a look kindly. Stackoverlow source code gets broken please find from here details: http://gist.github.com/5765529 [sun@example mysip]$ gcc myapp.c /tmp/ccEKxwjG....

C: local pointer variables change after sscanf problem

Hi I wrote a C code that a portion of it is: ... P *head=NULL,*cur=NULL; char Name,tmp[255]; int AT,ET; FILE *iF; if((iF=fopen(fileName,"r"))>0){ fgets(tmp,255,iF); sscanf(tmp,"Interval:%d\n",&quantum); fgets(tmp,255,iF); //waste while(!feof(iF) && fgets(tmp,255,iF)){ ...

Function is causing huge memory leak?

I have the following function: void CGlEngineFunctions::GetBezierOpposite( const POINTFLOAT &a,const POINTFLOAT &center, POINTFLOAT &b, float blength ) { POINTFLOAT v; v.x = a.x - center.x; v.y = a.y - center.y; float alength = GetDistance(a,center); if(blength == 0) { blength = alength; } fl...

Can't find error in pixel searching algorithm

Ok, I'm trying to make a program that finds the position of a colored pixel within the desktop. To do this I make a screenshot of the desktop then go through the pixels and search for the one that has the matching RGB as i need. The only problem is that my program returs strange coordonates X,Y for the found pixel... #include <stdio.h> ...