c

check is string is a substring of another string

How do I check if a string is a substring of another string in C without using the substr function? ...

Troubleshooting segmentation Fault

I am getting a segmentation fault in some C code, and I cannot figure out how to read this so I can figure out the problem.. Does anyone have any techniques that can help me? Does anything jump out to you? Here is gdb output: GNU gdb 6.8 for GNAT Pro 6.2.1 (20090115) [rev:143235] Copyright (C) 2008 Free Software Foundation, Inc. Lic...

Autoconf ignores compiler flags

I'm trying to build a C library with a non-native architecture. I'm running OSX 10.6 (which is x86_64) but I need the library compiled for i386. Normally, you can just add the compiler flag: -arch i386. But I'm using Autoconf and it ignores this in the configure file and it also ignores it if I try running: ./configure CC="gcc -arch i386...

Passing Arguments wrongly? C Question

When my TimerExpire function is finally called when the timer ticks out, it prints out gibberish. Anyone know why? But my printk function in IOCTL_MAKE_TIMER prints out correctly, so I think it's because I'm passing in the data wrong. setup_timer() works by setting up the timer in the first argument, telling it to call the function spec...

How can I get multiple calls to sem_open working in C?

I'm experiencing a lot of difficulty getting Semaphores to work on a Linux based system in C. The process of my application is such: Application starts Application forks into child/parent Each process uses sem_open with a common name to open the semaphore. If I create the semaphore before forking, it works fine. However, requiremen...

C program cross platform Differences on windows and Unix OS

Is there any difference in C that is written in Windows and Unix. I teach C as well as C++ but some of my students have come back saying some of the sample programs does not run for them in Unix. Unix is alien for me. Unfortunately no experience with it whatsoever. All i know is to spell it. If there are any differences then i should be ...

Socket programming problem in C

From the below piece of code, why I am getting Reading Socket for response int Read(int sock, char *p, int size) { int remain, read=0; remain = size; while (remain > 0 ) { if ((read = recv(sock, p, remain, 0)) < 0) { /* Error */ return(read); } else if (read == 0 || *p == 0x0a) { ...

Can I see defined macros during compilation of a C code?

I have a piece of code which compiles without problems with x86 gcc 4.4.1 but fails with blackfin gcc 4.1.2 with many "expected unqualified-id before numeric constant" errors. I see that there are some variable names that clash with some predefined macros. Is it possible to see defined macros at a certain line of a cpp file? ...

Case when blocking recv() returns less than requested bytes

The recv() library function man page mention that: "It returns the number of bytes received. It normally returns any data available, up to the requested amount, rather than waiting for receipt of the full amount requested." If we are using blocking recv() call and requested for 100 bytes: recv(sockDesc, buffer, size, 0); (where siz...

The Unreliable Signal API - Code doesnt work as expected

Basically,expected output of is that it catches KeyboardInterrupt 5 times and exits the 6th time.(If 1st line of handler() is un-commented) Now, if i comment that line too, then also the behavior of program doesnt change even though I am using unreliable API. As I have used signal() function, this is unreliable bcos after the...

System.nanoTime() equivalent in C

Possible Duplicate: C++ Timer function to provide time in nano seconds I need to get out of a loop when approaching 3 seconds, so I need to calculate the elapsed time. I'm moving some code from Java to C, and I was using the easy System.nanoTime() in Java, How would I do that in C? I noticed that time(NULL) will return the ...

macro and function conflict in C

What error is thrown when macro and function conflict in C arises? Is it a macro processor error or does this error occur due to some language violation? For example, in this code: #include <stdio.h> #define MAX(i, j) (i>j)? i : j int MAX(int i, int j){ return (i>j) ? i : j; } int main(){ int max = MAX(5, 7); printf("%d",max); ...

Clear tutorial explaining modular programming in C?

I'm just getting started with modular programming in C. I think I'm doing something wrong with the inclusions, because I'm getting a lot of conflicting types for 'functionName' and previous declaration of 'functionName' was here errors. I did put inclusion guards in place. Do you know a clear tutorial that explains modular programming i...

Typedeffing a function (NOT a function pointer)

typedef void int_void(int); int_void is a function taking an integer and returning nothing. My question is: can it be used "alone", without a pointer? That is, is it possible to use it as simply int_void and not int_void*? typedef void int_void(int); int_void test; This code compiles. But can test be somehow used or assigned to som...

bsearch function in c

If I have two functions: void SortStudents(char *studentList[], size_t studentCount) { qsort(studentList, sizeof(studentList)/sizeof(studentList[0]), sizeof(studentList[0]), Compare); } int Compare(const void *a, const void *b) { return (strcmp(*(char **)a, *(char **)b)); } That sort and compare using the qsort function, ho...

Gtk buttons over a Gtk drawing area

Hi! i' working with Gtk developing some app. I must put some buttons over a map. I'm drawing the map on a GtkDrawingarea, but i'm not able to put buttons over it. Any suggestion? Thanks ...

Datastructure and algorithm for merging multiple ranges of integer in C

I am working on a Computer Vision problem, in which I have to merge regions of an image. A region (or blob) is defined by its lines, i.e. the following region of O: 0123456789 0 XXXXOXXXXX 1 XXXOOOXXXX 2 XXXOOXXXXX 3 XXXOXXXXXX 4 XXXXXXXXXX is defined by : row: 0, cols: 4-4 row: 1, cols: 3-5 row: 2, cols: 3-4 row: 3, cols: 3-3 I ...

Can I implement callback from WCF based HTTP service to a gSOAP c/Linux client?

I have a Linux/c client app that connects to a WCF web service over HTTP/SOAP (BasicHTTPBinding). I am using gSOAP. Can I implement the calls to the web-service using callback? I want to get the data asynchronously as call back. Update: I have updated the question title. ...

Flaw in the strcpy sample program

I am using the following code to copy the string contents to another string. Two logics are used ,One with while loop(commented) is working and the other is not (as=at). Please help me to identify the flaw in this code. Thanks in advance #include<stdio.h> #include<conio.h> main() { char *s="SourceString"; char *t="TargetStri...

Eclipse CDT Custom Compiler Error Parsing Plugin

I'm using an uncommon C compiler with Eclipse CDT. I have a make file setup which is nice, but I'd like IDE integration with the error / warning output of my compiler. Does anybody know what steps I can take to write a plugin for parsing / supporting my compilers output? I think it should be easy but there is a barrier of entry of fig...