c

How do I properly reference the GNU readline library to scan terminal input?

I am attempting to compile C code that utilizes the following within GNU readline. #include <readline/readline.h>; #include <readline/history.h>; I've tried changing the <> to "" and compiling both with and without the -lreadline options. Nothing seems to work. When compiling without -lreadline under gcc results in the following being...

Declaring an array of negative length

What happens in C when you create an array of negative length? For instance: int n = -35; int testArray[n]; for(int i = 0; i < 10; i++) testArray[i]=i+1; This code will compile (and brings up no warnings with -Wall enabled), and it seems you can assign to testArray[0] without issue. Assigning past that gives either a segfault ...

Var arg list in main

I want to use my program like this: ./program -I /usr/include/ /usr/bin/ /usr/local/include/ ... Where the switch can go on and on like in a var args list. How could I do that in C99? Preferably get a something like char **args_list or char *args_list[] that contains all of the things like /usr/include and /usr/bin/. ...

C sentinel loop question

This program is supposed to judge the height of multiple buildings by the type of building and number of stories. There is a loop that continues to ask the questions until the user enters "0" for type of building. At the end, it prints a report showing the types of buildings and how many of each conform to building codes. I am having pro...

Get length of string array of unknown length

I have this function: int setIncludes(char *includes[]); I don't know how many values includes will take. It may take includes[5], it may take includes[500]. So what function could I use to get the length of includes? ...

Confusion in C program

Is the given program well defined? #include <stdio.h> int main() { int a=2,*f1,*f2; f1=f2=&a; *f2+=*f2+=a+=2.5; *f1+=*f1+=a+=2.5; printf("\n%d %d %d\n",a,*f1,*f2); return 0; } ...

ANSI C vs other C standards

On several compilers I have used (all gcc but various versions) I get a C99 mode error for things like declaring int i inside the for loop expression instead of before it (if I do not use the std=c99 option). After reading here I understand that the gcc options -ansi, -std=c89, and -std=iso9899:1990 all evaluate to the ANSI C standard, ...

Making file wrap around when using fwrite

I am using an embedded system running linux.I use a ramdisk filesystem on the embedded target. My application captures real-time data and does Standard C "fwrite" to a file in this ramdisk fs.As there is limited amount of memory , I would like to set a max size for the file and cause fwrite to wrap around like a circular buffer. Is there...

a simple getch() and strcmp problem

I have this simple problem that gets an input from the user using a function then checks if the input is 'equal' to the "password". However, strcmp would never return my desired value, and the culprit is somewhere in my loop that uses getch() to take each character separately and add them to the character array. I found this out by havin...

cgi with c programming

I'm trying simple example - #include <stdio.h> int main(void) { printf("Content-type: text/html\n\n"); printf("<html><title>Hello</title><body>\n"); printf("Goodbye Cruel World\n"); printf("</body></html>"); return 1; } compiled and moved to apache docroot - but when i click on url - it comes as a popup and asks where to down...

Converting an int into a 4 byte char array (C)

Hey, I'm looking to convert a int that is inputed by the user into 4 bytes, that I am assigning to a character array. How can this be done? Example: Convert a user inputs of 175 to 00000000 00000000 00000000 10101111 Issue with all of the answers so far, converting 255 should result in 0 0 0 ff although it prints out as: 0 0 0 ffff...

Python3 int, long unification implementation

I just read through a PEP concerning the unification of ints and longs in Python3k in PEP 237. The approach used in this seems very interesting. The approach is to create a new type "integer" which is the abstract base class of int and long. Also, performing operations on ints which result in very large numbers will no longer result in a...

get rhythmbox information from other user

I have Rhythmbox running on my desktop, and I want to be able to control it from remotely via a web interface. I'm having problems accessing it, however, because rhythmbox-client is complaining that the user (www-data) that is trying to access it doesn't a) have as X session running, and b) doesn't have access to my rhythmbox dbus inform...

Difference between API and ABI

I am new to linux system programming and I came across API and ABI while reading Linux System Programming. Definition of API : An API defines the interfaces by which one piece of software communicates with another at the source level. Definition of ABI : Whereas an API defines a source interface, an ABI defines the low...

initialization discards qualifiers... sdl warning

When I run this bit of code through GCC I get this warning on the line where I set info to SDL_GetVideoInfo(). warning: initialization discards qualifiers from pointer target type int main(int argc, char** argv) { SDL_Init(SDL_INIT_EVERYTHING); SDL_VideoInfo* info = SDL_GetVideoInfo(); int SCREEN_WIDTH = info->current_w; ...

Why does left shift operation invoke Undefined Behaviour when the left side operand has negative value?

In C bitwise left shift operation invokes Undefined Behaviour when the left side operand has negative value. Relevant quote from ISO C99 (6.5.7/4) The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1× 2E2, reduced modulo on...

scanf erratic behaviour

I compiled and run the following console program which is supposed to read an integer and return the number of field successfully read: # include <stdio.h> int main ( void ) { int result, number; printf ( " Enter an integer : \n "); result=scanf ( " %d " , & number ); printf ( " Fields read % d " , result ); return 0; } I compi...

Checking what the input is like then using scanf (C)

So the issue is the user can either give input that is one int, or the user can give an input with three int. And it all depends on the first input. Little confusing so here is an example: printf("Please enter input in this format: (-blackwhite | -color) colorvalue"); user inputs "-blackwhite 40" so I want to scanf("%s %u", charArr...

how to change directory using exec command from C program?

Hi, I have to change working directory from my C program. For this I have used the following command: execl("/bin/cd","cd","..",(char*)0); but this command is not changing the directory? Is anything wrong in this command or is there any other way to change working directory from C program? ...

Difference between using a macro and its expansion

#define ADD(a,b) (a)+(b) void foo1() { int a=1, b=2; int k=0; while(k++ < 10000) { int c = ADD(a,b); a = c; } } void foo2() { int a=1, b=2; int k=0; while(k++ < 10000) { int c = a + b; a = c; } } what is the difference between foo1 and foo2. Someone asked me this...