c

Fork() not working to calculate last few digits of command line arguments.

I' m trying to calculate the total sum of a line of command arguments entered in from the terminal. Thus far, I've gotten to the point where it will print out everything until the very last few digits. I have to make use of fork() to do all of the computation with my companion program. The main program is unable to do any computation for...

C Programming - Convert an integer to binary

Hi guys - i was hopefully after some tips opposed to solutions as this is homework and i want to solve it myself I am firstly very new to C. In fact i have never done any before, though i have previous java experience from modules at university. I am trying to write a programme that converts a single integer in to binary. I am only al...

[C++] Mixing extern and const

Can I mix extern and const, as extern const? If yes, does the const qualifier impose it's reign only within the scope it's declared in or should it exactly match the declaration of the translational unit it's declared in? I.e. can I declare say extern const int i; even when the actual i is not a const and vice versa? ...

Mac OS. How to create image from PNG data?

Hi, all! I have an array of data that represents PNG: unsigned short systemFontTexture[] = { ... 0x5089,0x474E,0x0A0D,0x5089,0x474E,0x0A0D,0x5089, 0x474E,0x0A0D,0x5089,0x474E,0x474E,0x0A0D,0x5089, 0x474E,0x0A0D,0x5089,0x474E,0x474E,0x0A0D,0x5089, ... } Can I create PNG file using this data? If yes, then HOW? ...

Macro for concatenating two strings in C

Hey, I'm trying to define a macro which is suppose to take 2 string values and return them concatenated with a one space between them. It seems I can use any character I want besides space. for example: #define conc(str1,str2) #str1 ## #str2 #define space_conc(str1,str2) conc(str1,-) ## #str2 space_conc(idan,oop); space_conc woul...

Implement piping ("|") using C..(fork used)

#include<stdio.h> #include<unistd.h> #include<stdlib.h> int main(int argc,char **argv) { int fd[2]; pid_t childpid; pipe(fd); childpid=fork(); if (childpid == -1) { perror("Error forking..."); exit(1); } if (childpid) /*parent proces*/ //grep .c { wait(&childpid); //...

calloc and copying data into memory area using c

I'm trying to allocate a block of memory and then copy data into that space. I made this simple program and it doesn't do what I expect it to do. Could someone please point out my faulty reasoning. Thanks. #include <stdio.h> #include <stdlib.h> void main(void) { int t1 = 11; int t2 = 22; int *bufptr; bufptr = calloc(2, sizeof(int)); ...

Combining Java and C without gcj -- move C to Java or Java to C?

First, I have no experience doing this. But like the beginning of any good program, I have problem that I need to fix, so I'm willing to learn. So many of you are probably already familiar with pdftk, the handy utility for handling various pdf-related tasks. So far as I can tell, most of these features are available in much newer, light...

Is there rule of thumb for catching errors in Lex/Yacc parsing?

Should we catch errors while parsing general purpose language as early as possible (in Lex) or where it is more convenient and give us more information (in Yacc)? How various languages solve this problem? ...

scanf() resetting first result depending of variable declaration order

Why does this not work as expected? int main() { unsigned char louise, peter; printf("Age of Louise: "); scanf("%u", &louise); printf("Age of Peter: "); scanf("%u", &peter); printf("Louise: %u\n", louise); printf("Peter: %u\n", peter); return 0; } Outputs: Age of Louise: 12 Age of Peter: 13 Louise:...

Trouble with reversing the order

I am trying to print out binary number in c however the dilemma i have is that its printing out in the reverse order. I have defined a function to tell me how many bits there are, this way i can work from the last bit back to get the nth bit i can use (value >> totalNumberOfBits) & 1; in a while loop i can run this until the totalNu...

How to convert concatenated strings to wide-char with the C preprocessor?

I am working on a project where I have many constant strings formed by concatenation (numbers, etc.). For example, I have a LOCATION macro that formats __FILE__ and __LINE__ into a string that I can use to know where I am in the code, when printing messages or errors: #define _STR(x) # x #define STR(x) _STR(x) #define LOCATION _...

Where is the C auto keyword used?

In my college days I read about the auto keyword and in the course of time I actually forgot what it is. It is defined as: defines a local variable as having a local lifetime I never found it is being used anywhere, is it really used and if so then where is it used and in which cases? ...

array of N pointers to functions returning pointers to functions.....

This was asked to me in an interview! i really got confused How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters could anybody please help? ...

Macro / keyword which can be used to print out method name?

__FILE__ and __LINE__ are well known. There is a __func__ since C99. #include <iostream> struct Foo { void Do(){ std::cout << __func__ << std::endl; } }; int main() { std::cout << __func__ << std::endl; Foo foo; foo.Do(); return 0; } will output main Do Is there any macro / keyword that would output...

C 3d array dynamic memory allocation, question, need help

Hi. I was looking through the web for a way to dynamically allocate space for 3d matrix, say of int type. And i found many sites concerning 2d matrices, and this one http://www.taranets.com/cgi/ts/1.37/ts.ws.pl?w=329;b=286 And there was this example as shown down. I understood all of above examples but this concerning 3d i cannot. Is ...

c variable seems to be printing address instead of variable value

#include <stdio.h> #include <stdlib.h> int main (void) { double f; printf ("What is the temperature in Fahrenheit?\n"); scanf ("%d", &f); double x = (f-32)*(5/9); printf ("%d degrees Fahrenheit \n",f); printf ("%d degrees Celsius",x); system("PAUSE"); return 0; } f seems to be printing address of variable f instead of the value...

Can i use the ordering methods of simple linked lists into a hash list?

Im confused with this question? Thank you in advance. Programming in C under linux ...

Setting std=c99 flag in GCC

I was wondering if there were any files in which I could set the -std=c99 flag, so that I would not have to set it for every compilation. I am using GCC 4.4 on Ubuntu. ...

Is the ANTLR3 C Target Thread Safe?

Hi, Is the ANTLR3 C Target Thread Safe? Thx ...