c

c qsort seems to remove last value in array

I am using the built in qsort to sort an array of structs. But after the call to qsort the last element in the array seems to have had its value that I am sorting by set to empty. Here is my code... int numEntries = 5; TvEntry* entries[numEntries]; //create array //Entries get added to the array here... qsort( *entries, numEntries, s...

Seg fault? Can you find it? cause I can't

I've looked over this about 15 times by now to no avail. I cannot understand why this is seg faulting? It doesn't even get to the "print" statement which makes no sense. the error codes actually do work tho (when I dont have a shared memory present) I have a load.c program but it works perfectly (im 100% sure of this) #include <stdio.h>...

C what the function of this function?

why 9 is a must in char input[9] int getInput (void) { char input[9]; fgets(input, 9, stdin); return atoi(input + 6); } void printHeader(void) { printf("Content-type: text/html\n\n"); printf("<html>\n"); printf("<head>\n"); printf("<title>%s</title>\n", PROGRAM_NAME); printf("</head>\n"); printf("<b...

Looking for improvement ideas

Hello, gcc 4.4.4 c89 Is there a better way to do this? I have the following code to read in from a text file. The text file contains lines like this: 4 5 6 1 5 7 5 9 5 3 5 7 8 3 2 3 7 2 3 4 5 3 7 9 3 2 5 6 I have given only 2 lines example, but there could be more and each with different lengths. What I need to do is get the numb...

What argument type does sscanf expect for a character class?

I've been trying to get sscanf to recognize a fairly simple format using character classes. I've noticed that when I provide sscanf with a char* to match the character class it overwrites the previous byte also as if it expected a pointer to 2 bytes. A simplified version of what I'm trying to accomplish: #include <stdio.h> int main(vo...

What IDE / compiler combination should a Linux user use to build Qt apps on Windows while avoiding MS Visual Studio?

I can't help it; I know many people will disagree, but I would really like to avoid Visual Studio as much as possible. My ideal combination would be gcc + Netbeans. I already use those to code in Linux. But my issue is compatibility. For example, there is a library that I want to use that is supposed to work for .NET and Java. Does this...

Error in a simple C code (pointers)

In the follwoing code, using libxml libraries : key = xmlNodeListGetString(doc, cur3->xmlChildrenNode, 1); if (flag == 1) { image2 = key; printf("the image 2 is %s \n", image2); flag = 2; } if(flag == 0...

Recording and charting boot process information in Linux

Hello everyone. I need to write a command line tool that records the boot process information in Linux, and then renders it in a chart format (a textual chart would do). How do I programmatically obtain the this boot process information? Languages that I am allowed to use are C and C++. Thanks in advance. :-) ...

graphics.h programs not running in Dosbox Windows 7 environment

I have installed Dosbox to run Turbo C in it. But my graphics.h programs are not executing in it. I am getting Linker Error which says"Undefined sumbol initgraph in module..." and so on. please help me to solve this problem. Thanks in advance. ...

c cgi how to get form

how to get form input(POST) with following conditions? 1. not hard code the content length 2. a function with provided param which is the form elements name, finally return the string i can't find any example on internet~ thanks ...

What does glOrtho(-1, 1, -1, 1, -1, 1) accomplish?

I'm reading the documentation for glOrtho and not understanding it. I'm looking at this resize code for an 2D drawing and not getting why some of the index are positive and some negative. The drawing is supposed to stay flat so I don't know if its doing what's supposed to: void reshape(int width, int height) { glViewport(0, 0, wi...

*glibc detected double free or corruption() * message!

The following deleteNode function when I run the program gets these: * glibc detected free(): invalid next size (normal): 0x000000000103dd90 ** Even i make the ' free(here); ' a comment,i get the above message. I dont think that the other 'free' calls provokes a problem like that. But I cant see why this would be wrong. :/ struct List...

Linux kernel module compiling

Hello, I try to compile simple linux kernel module: #include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk("Hello world 1.\n"); return 0; } void cleanup_module(void) { printk(KERN_ALERT "Goodbye world 1.\n"); } My makefile: obj-m = testmodule.o KVERSION = $(shell uname...

Dynamic list in ANSI C?

Am i right in thinking the only way to create a list which grows during run time in C, is to use a linked list? ...

Convert C uint8_t pointer to C# byte array

Hi, I have exported the following C function to be invoked in a DLL file. uint8_t* _stdcall GetCurrentImage(); Now I want to call this function in C# to get a bitmap Image. How can I do this? Thanks in advance! ...

What happens if a program runs also its comments??!!

It seams very weird to me.I cant really understand whats happening. I had a false on my code,decided to put a part of it on /*...*/ BUT when i run the program... this part of code is also executed!!! EDIT: well this is the code i put in comments as you can see: /*int menu() { int code; while (1) { // printf("\nGive code:"); // s...

Speeding up large switches and if-elses

What can I do to improve large switches and if-elses speed manually? I will probably need some kind of hash or lookup table. I'm working with gcc and C code, I doubt that gcc has any inbuilt optimizations for this. Edit: My switch code is what every switch looks like, do something based on if a particular int is some value. My if-elses...

How to pass parameter to a c console program using Xcode ?

Hello, with other IDE, you can pass parameter to the program via the IDE (it save times instead of typing hello.c parameter1 parameter2 in the shell) Is there any way to pass parameters to the program trhough the Xcode IDE instead of just clicking on "RUN" then "CONSOLE" (which provide no arguments to the program) Thanks ...

C++: Is there a way to avoid redundancy with changing long declarations?

This has always bugged me with C and C++: In my header file I have something like: bool UpdateWindow( int w, int h, char bpp, bool force, char* someOtherLongStuff ) Now, if I want to change that for whatever reason, I have to do so in both header and source file - that's annoying in my opinion. Is there a way to automate this? I'm ...

Understanding the '&' operator.

Hi. As of what I know about '&' operator, it returns the base address of the operand in memory. Let us imagine the following scenario (as on my machine): sizeof(int) = 4 bytes sizeof(float) = 4 bytes sizeof(char) = 1 byte Now, if I write something like this: void main() { int i = 5411; int *ip = &i; char *c = &i; printf("%d",*...