When I run the code you showed us in message #8 in this thread, the output I get is:
As you can see, this is considerably different from the output you said you got from this code in message #6 in this thread. But, most importantly the roll_num values shown while walking the linked list match the values found in your input file. I'm not doing anything with atoi(), calloc(), exit(), fclose(), ferror(), fgets(), fopen(), fprintf(), free(), malloc(), printf(), strlen(), or strncpy() that should behave differently on OS X than it should on any Linux distribution. I can't see how you would get the values for roll_num that you showed us in message #6 in this thread from the code you posted in message #8 in this thread.
Last edited by Don Cragun; 02-10-2014 at 08:28 PM..
Reason: Remove duplicated text from cut & paste error.
This User Gave Thanks to Don Cragun For This Post:
Just in case I forgot some lines that may have been modified, here I copy and paste the same code of my post #8 and compile in another PC with same Ubuntu:
This is almost the same of your output of post #9, that roll_num are wrong except the first one, very similar to post #6 where the first half was not shown. I will try more test. Anyway, gdb is the another one that I am trying to get familiar with at the meantime.
And thank you pointing out that I'm not doing anything with atoi() , calloc() , exit() , fclose() , ferror() , fgets() , fopen() , fprintf() , free() , malloc() , printf() , strlen() , or strncpy() that should behave differently on OS X than it should on any Linux distribution. which I have no experience how they may cause difference.
Now that you have finally shown us the output from the first part of my code, it is obvious that something is overwriting the roll_num member of struct student (after the first element in the linked list) with a pointer. If you convert the bad values in roll_num from decimal to hexadecimal you'll note that the value is between the values of the pointers assigned to temp->name and temp->next.
For example 24736352(decimal) == 1797260(hex) and the pointer assigned to head is 17297250(hex) and the pointer assigned to head->name is 1797270(hex).
This should make absolutely no difference, but please try changing:
to:
Assuming that doesn't make any difference, while you're exploring gdb watch what gets assigned to temp->roll_num.
I am using Solaris 10u11 on x86 machine, i am root, i want to use a gcc compiled code to use read10/write10 function of USCSI solaris library to access data from a normal USB mass storage device.
I am able to open a device prior to sending USCSI command via IOCTL.
IOCTL command works ok as... (0 Replies)
How can I use malloc with copying/creating files?
Is this the correct way?
I'm a bit confused...
int in_fd;
int *out_fd;
char buffer;
in_fd = open(av, O_RDONLY);
out_fd = malloc(strlen(av)+strlen(av)+2);
sprintf"(buffer,%s/%s", av,av); (5 Replies)
hi
One of our SCO 5.0.6 server is crashing every second or third time during rebooting with kernel panic.
According to this SCO manual:
http://wdb1.sco.com/kb/showta?taid=106181&qid=1689366546&sid=504668569&pgnum=1
I've saved dump image into a floppy and I've done the following steps:
#... (0 Replies)
Hi,
I have a following problem in C.
I have a function A in which I used to call another function (function B) and pass an array of values through array variable by using below:-
foo=functionB(array);
In functionB, i used to just return some "values" (e.g return num;) in order to pass... (1 Reply)
Hi
When im listing (ls -al ) its listing directories without / at the end of directories
dir1 dir2 dir3
and i need to list directories with
dir1/ dir2/ dir3/ and this should not be made by command ls -F
/ should be embedded at the last
since one of the scripts reads directories... (1 Reply)
Hi All,
These are the two ways i tried to read file but i getting work with second one not with the first.
char buf; // Defining space for buf
ctrlfnum = fopen(filename_arr.control_fname,"r");
1) n = fread(buf,sizeof(buf),1,ctrlfnum); ============== (not works)
2) n =... (4 Replies)
Hi folks,
Need your help.
I am writing a KSH script to read a few commands from a file & execute.
I am using the following code to read the file line by line & excute each command. When I am printing each line I see it is printing properly but while excuting, the particular "ps" command... (5 Replies)
Hi,
I want to read the task_struct structure in Linux in order to get the names & pids of all processes.
How can this be done??
Thanks in adv,
molu (4 Replies)
Hello,
I am having a problem setting a range of numbers for the "case" structure.
I can use with no problems, but
when I use it doesn't work???
Does the case struture allow numeric ranges?
eg:
echo -e "enter number between 0 and 60: \c"
read $answer
case $answer in
) echo... (2 Replies)