c

Reading a sentence from stdin using fgets

I've written the following code to read a line from a terminal window, the problem is the code gets stuck in an infinite loop. The line/sentence is of undefined length, therefore I plan to read it in parts into the buffer, then concatenate it to another string which can be extended via realloc accordingly. Please can somebody spot my mi...

Getting a substring in C

I have a string in the following format: "R: 625.5m E:-32768m" What's the most efficient way to pull out the 625.5? ...

Is -5 an integer literal?

[title] or is 5 a literal, and -5 is an expression with unary minus taking a literal as an argument? The question arose when I was wondering how to hardcode smallest signed integer values. TIA. ...

getenv(QUERY_STRING) in C CGI

C file: #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { FILE *ptr; char m[200]; char *data = malloc(200); data=getenv("QUERY_STRING"); sscanf(data,"%s", m); printf("%s", m); ptr=fopen("c:/test.txt", "w"); fprintf(ptr, "%s", m); fclose(ptr); return 0; } //gcc -g print.c -o print.exe HTML ...

c++ cpp conversion from 'myItem*' to non-scalar type 'myItem' requested

i have this code struc MyItem { var value MyItem* nextItem } MyItem item = new MyItem; And I get the error: "c++ cpp conversion from 'myItem*' to non-scalar type 'myItem' requested" Compiling with g++ Any ideas? Thanks! ...

Determining sprintf buffer size - what's the standard?

When converting an int like so: char a[256]; sprintf(a, "%d", 132); what's the best way to determine how large a should be? I assume manually setting it is fine (as I've seen it used everywhere), but how large should it be? What's the largest int value possible on a 32 bit system, and is there some tricky way of determining that on th...

Is it common for a language to evalute undefined as equal to false? If so, why is this done?

UPDATE: Question still unanswered. @Alastair_Pitts: Unless I'm missing something, it's a two part question. The second part, "If so, why is this done?" and not been answered. Believe the question is clear, but if you have any questions -- just let me know. Thanks! undefined = unknown and is a reference to system based on ternary logi...

How to check for rounding off errors?

Hello All, This may be a dumb question to ask: While using float there is some rounding off done for decimal places, how to check for rounding off errors preferably in java or C? Any suggestions will be greatly appreciated. ...

how can I remove a flag in C?

There is a variable that holds some flags and I want to remove one of them. But I don't know how to remove it. Here is how I set the flag. my.emask |= ENABLE_SHOOT; ...

What is wrong with using turbo C?

Hi all, I always find that some people (a majority from India) are using turbo C. I cannot find any reason to use such outdated compiler... But I don't know what reasons to give when trying to tell them to use modern compiler(gcc,msvc,...). ...

Custom memory allocator/manager in C ? which approach?

I looking for some (custom) memory managers/allocator written in c and went through some articles, - Some Links : IBM - Inside memory management Valgrind - How to Shadow Every Byte of Memory Used by a Program Stack Overflow Question - Write your own memory manager ned Productions - nedmalloc Homepage Two-Level Segregate Fit (TLSF) - W...

Quickly searching a doubly linked list

Hi, I currently have a simple database program that reads keys in from a text file and stores them in a doubly linked list (values are read later if they are required). Currently, I do a sequential search on the list, but that is clearly rather slow. I was hoping that there is another way to do. I was reading about binary trees (in parti...

How to Convert a 12-bit Image to 8-bit in C/C++?

All right, so I have been very frustrated trying to convert a 12-bit buffer to an 8-bit one. The image source is a 12-bit GrayScale (decompressed from JPEG2000) whose color range goes from 0-4095. Now I have to reduce that to 0-255. Common sense tells me that I should simply divide each pixel value like this. But when I try this, the ima...

In C/C++, is char* arrayName[][] a pointer to a pointer to a pointer OR a pointer to a pointer?

I understood multi-dimensional arrays as pointers to pointers, but perhaps I am wrong? For example, I though: char * var = char var[] char ** var = char* var[] or char var[][] char *** var = char var[][][] or char* var[][] or char** var[] Is this incorrect? I was confused because I saw a char*[][] cast as a char** in a simple...

C - pseudo shell and concurrency

I'm writing a pseudo shell program which creates a child from a parent process. The parent process waits for the child to finish before continuing. My forking code looks something like this: if(fork()==0) { execvp(cmd, args); } else { int status = 0; wait(&status); printf("Child exited with status of %d\n", status); ...

Still reports "undefined symbol: new_add" after use "objcopy --redefine-sym add=new_ad"

Hi, I need to load two dynamic libraries and there is one function name confliction. So I use the the command "objcopy --redefine-sym add=new_add libmy_test.so libmy_test_new.so" to modify the symbol name. But it still reports "Error: ./libmy_test_new.so: undefined symbol: new_add" The following are my test codes. void *lib_handle2 = ...

Does posix aio in linux 2.6 support socket file descriptor?

I've seached such question in google and got different answers.I cann't determine whether posix aio in linux 2.6 support socket file descriptor or not. if it support tcp socket,does the aiocb.aio_offset=0 relative to the first byte readed from the tcp socket fd? if it doesn't,does any asynchronous io library in linux support socket fd?...

How to debug C DLL when called from a C# application in Visual Studio 2008

I have a C# windowed application that needs to make use of a third-party API, which is offered only in C. To solve this problem, I've created three projects within VS2008: two C# projects and an empty C++ project. One C# project is my "Wrapper" project, responsible only for producing managed code that calls the C DLL. The other C# pro...

Visualising C structs?

Hi all, I am using Ubuntu 10.04, and studying programming of kernel objects. I have come across some rather complicated structs which I have difficulties reading, so I thought I'd try to find some tool that can help me visualise them. Only thing I could find so far is VCG, which has a C Struct Visualization Example, which looks like...

Structures and Pointers in C - crash when using strcpy

I have an assignment that is supposed to be written in C (not C++), in which I need to create some structs from reading multiple text files. I have learnt c before (2 years ago) - I'm far more comfortable with Java, just can't use that for this project. I guess my issue comes from not understanding the pointer syntax very well :/. Howeve...