Log in

c coder's Journal

> recent entries
> calendar
> friends
> profile
> previous 20 entries

Saturday, May 19th, 2012
11:43 am - Holy WTF?!

I have found what I think is a bug in the GNU stdlib functions atoi(), atol(), and strtol().

I'm using: gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3

Read on, if you dareCollapse )

{ [2] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Friday, March 26th, 2010
12:21 pm - Hello

I'd really like an online teacher/tutor/guider for c? I'm struggling really hard with it and I would love to know if anybody would like to help me. If it helps any, I'm working on a Human to Zombie translator :D

Thanks for any help!

{ [6] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Sunday, January 3rd, 2010
8:00 pm

а существует ли способ откомпеллировать прогу, написанную на SML (Standart ML of New Jersey) и превратить ее в файл на Си?


{ fgets(buf,MAXSIZE, stdin); }

Friday, January 16th, 2009
10:22 pm - hey

o hai

So I'm using gcc and want to do do away with the data segment and relocate symbols. Let me explain.

the code is for an architecture that only has ram at 0xff0000

$ ld stuff.o main.o -Tdata 0xff0000 -e 0 --oformat binary -o pants.bin

works fine but it produces a bloody huge output file. The data segment is empty and does not need initialization. So
basically I am wanting to relocate data symbols to start at 0xff0000 an only output the text segment from my linker. Has anyone done this before? any ideas?

{ [3] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Wednesday, October 29th, 2008
6:37 pm - Linux Specific Question

In the very near future I may need to write a custom device driver for an embedded Linux project.

Assuming a memory mapped device, I'm thinking a user space driver with a custiom ui (ie myopen(), myread(), mywrite() instead of using open(), read(), write() etc) will be easier and faster than linking to the kernel. My questions are:

1) If it's a user space driver does that mean it does not have to be recompiled for a different version of Linux?

2) Am I correct in assuming a user space program can in fact do memory mapping to absolute bus addresses?

3) This project is allegedly real-time, but for the first iteration I'm thinking of using named pipes inside wrapper functions for the IPC, suggestions for more efficient (ie faster) IPC would be appreciated.

I've worked on many real-time and/or embedded kernels, and written many device drivers, but this will be be my first Linux project.


{ [2] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Monday, May 26th, 2008
9:40 am - Working with connection-oriented sockets.


Hi, all.

I'm having difficulties with a homework assignment whose intent is to implement a client/server service that will respond whether a remote host is up or not.

For example, a user who types:
>myping atrium99

accesses the myping client which contacts the myping server on atrium99. The user would get the response:
myping: 2:24pm up 110 day(s), 23:17, 13 users, load average: 0.51, 0.42, 0.50

The myping server running on a host CPU (like atrium99) listens at its well-known port for client requests. The server forks a child to respond to the request. The original server process continues listening at the socket. (Assume that the myping well-known port number is defined by the constant MYPINGPORT.)

When I submit my code to ToTeach (a LAN-based automatic program homework checking system), I get a very ambiguous error:
Your code had a nonzero status exit or it hung or see below
The client program had a non-zero exit status

However, I continue to get this message even when I change all of my exit() statements to return 0 values.

Can someone please take a look at ( my code ) and tell me what I'm doing wrong?

Thanks so much!


current mood: sleepy

{ [5] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Monday, April 7th, 2008
3:46 pm - unknown construction

While I was digging up some sources(mpd daemon for FreeBSD to be more precise) i had found this:

u_char want_protocomp:1; /* I want protocol compression */
u_char want_acfcomp:1; /* I want a&c field compression */
u_char want_multilink:1; /* I accept multi-link */

I know the " ? : " operator
and "::" operator but not just single conon mark.

Does anybody know what can this mean?

{ [9] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Saturday, February 23rd, 2008
7:53 pm - Printf-ing a char[] field of a struct.


So I hadn't programmed in C for a while, so I thought I'd undertake a small just-for-fun project in it. Almost immediately, I ran into a strange wall. Behind the cut is a short program that demonstrates the problem I'm having (using GCC 3.2.3 for MinGW).

short sample programCollapse )

I just don't get it — it seems like all four groups should work exactly the same (aside from the extra " - 0" in the fourth one, which is only there to demonstrate that I do have a null byte there). Especially the second and third groups: how the heck could those differ from each other? (Obviously this is completely workaroundable, so it's not a big deal; but still, I'd like to understand what's going on!)

Thanks in advance for any thoughts. :-)

{ [14] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Tuesday, December 4th, 2007
6:26 pm - path...
finatronics I'm trying to figure out how to get the original path to a header file as a string in my program for version-control purposes...

I've tried using the predefined __FILE__ macro, but it's only giving me the filename itself "fileInfo.h" and none of the path info. Most important, actually, is the folder name the file is contained within, I don't even care about the filename!

unnecessary detailsCollapse )

The odd thing is, I can find a whole bunch of sites claiming that __FILE__ is supposed to be the entire path, but it's obviously not in my case. I'm using [avr-]gcc version 4.1.2

Ideas? Thanks!

{ [10] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Friday, November 30th, 2007
11:02 am - k=R(2ed) 1-9 took me liek 4 hours!!!

is it normal for someone learning programming to have moment liek WTTF!!! where you stare at the screen? I just did not get this exercise......and felt the buildup to it was weak as far as rpeparing em for it....and this is suppsoed to be the greatest programming book ever written!!!  maybe Im a tard?  did you all just bang get this exercise and move on?

current mood: anxious

{ fgets(buf,MAXSIZE, stdin); }

Monday, November 19th, 2007
8:34 pm

I'm writing a simple program that will read a line and identify the first and last name as two separate variables in the same line. What would be the most effective way to do this?

I was thinking of having the scanner find the space in the line, and identify the characters BEFORE the space as the first name, and the characters after the space as the last name - but I have no idea how to go about this.

I'm using a sscanf function that reads the line. Is there a specifier that identifies spaces, or are they read the same way as characters?

{ [5] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Wednesday, October 31st, 2007
1:14 pm - approximating bessel functions

Below are two functions -- both intended to calculate approximations to functions of modified Bessel functions of the first kind based on Abramowitz and Stegun. I've switched to using these because they are able to able handle larger magnitude input than bessel_i from the Rmath library, which we had been using, which in turn is based on Netlib. First, I wonder if anyone knows of better approximations for large x. Second, any general comments on the code would be welcome. Thanks much.

codeCollapse )

{ fgets(buf,MAXSIZE, stdin); }

Saturday, October 6th, 2007
12:37 pm - flags to ensure portability?

Which compiler flags if any (apart from -Wall) do you use in compiling your C code with gcc in order to ensure maximum portability (across platforms, versions, and compilers)? What do you think of using -std=c99 -pedantic or -ansi -pedantic? Thanks!

{ [2] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Sunday, June 10th, 2007
12:54 pm - homework help

I need help on my last assignment for my programming class. I have all the logic, I just forgot how to use -1 to end a string. and I need to put it in a function. I'm supposed to get a string of numbers from 1-9 and output a histogram. so say you enter 1 2 3 7 5 4 2 1 1 the program should output:
1: ***
2: **
3: *
4: *
5: *
7: *

it's due tonight by midnight.
here is what i haveCollapse )

{ [43] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Sunday, May 20th, 2007
2:02 pm - help

Just joined the community in hopes that I can get some homework help.
I am a Computer Science major at Portland Community College and am currently taking Intro to C.
If you want to help, send an email to:
and I will tell you the details of the assignment and the code I have so far

{ [4] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Wednesday, May 9th, 2007
7:46 pm

There wouldn't happen to be a shorter way to write:

else if((tictac[0][0]=='O' || tictac[0][0]=='X')&&(tictac[0][1]=='O' || tictac[0][1]=='X')&&(tictac[0][2]=='O' || tictac[0][2]=='X')&&(tictac[1][0]=='O' || tictac[1][0]=='X')&&(tictac[1][1]=='O' || tictac[1][1]=='X')&&(tictac[1][2]=='O' || tictac[1][2]=='X')&&(tictac[2][0]=='O' || tictac[2][0]=='X')&&(tictac[2][1]=='O' || tictac[2][1]=='X')&&(tictac[2][2]=='O' || tictac[2][2]=='X'))

would there?


current mood: curious

{ [11] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Saturday, March 3rd, 2007
5:40 pm - In dire need of help. ;.;

So i've been starring at this code and manipulating it for who knows how many hours now and it's finally beginning to drive me insane.

The program is supposed to sum up a bunch of grades and then calculate the average, but the average always comes out to be 16. I am blind to see the problem in code thus far. Any suggestions?

int main(){

int i = 0;
float SumEx = 0;
float AvgEx;
float OneExVar;

printf("Enter exam value:\n");
scanf("%f", &OneExVar);

while(SumEx >= 0){

printf("Enter next exam value:\n");
scanf("%f", &SumEx);

i = i + 1;


AvgEx = (SumEx + OneExVar)/(i + 1);

printf("The average is: %5.2f\n", AvgEx);


current mood: frustrated

{ [11] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Thursday, March 1st, 2007
2:41 pm - SIGFPE

What's the deal with SIGFPE?
I tried to install a signal handler to catch things like divide-by-zero, or sqrt(-1), but no SIGFPE is raised - on cygwin, sparc, ppc64. I tried to search this on google, but could not find anything useful.
What is the way to handle this? In C. Portably. code below the cutCollapse )

{ [17] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

Wednesday, December 20th, 2006
5:37 pm - C compiler on-line

Hi, guys!
Could you tell me please, is there any c-compiler avalible on-line?
I would like to work on my programs from random computers, but not always compilers are installed there (and I can't install by myself, because I don't have permissions).

Thanx for any idea :)

{ [6] fprintf(stdout, buf); || fgets(buf,MAXSIZE, stdin); }

> previous 20 entries
> top of page