473,399 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

help with C

I need to insert and sort in a link list

Nov 20 '05 #1
21 1391
sulays wrote:
I need to insert and sort in a link list


how far have you got so far with your problem? Could you show us the
code you
have written so far or explain what you have are having difficulties
with?
--
Nick Keighley

Nov 20 '05 #2
in getting an infinite loop dont know why?

this is in main
while(!feof(fpA))
{
readingaemployeedata(&fpA,lastn,firstn,midini,&emp id,title,balance);
if(feof(fpA))
break;
tempPtr =
creatingaemployeedata(lastn,firstn,midini,empid,ti tle,balance);
while(tempPtr != NULL)
{
prinheader();
firstemployeePtr = inserting(firstemployeePtr,tempPtr);
printing(firstemployeePtr);
}

function

EIS* inserting(EIS *fPtr,EIS *tempPtr)
{
EIS *prev = NULL;
EIS *curr = NULL;

if(fPtr == NULL)
return tempPtr;

curr = prev = fPtr;

while(curr != NULL)
{
if(strcmp(tempPtr->lastname,curr->lastname) > ZEROI)
{
tempPtr->nextnode = curr;
if(curr == prev)
return tempPtr;
else
prev->nextnode = tempPtr;
return fPtr;
}
else
{
prev = curr;
curr = curr->nextnode;
}
}
prev->nextnode = tempPtr;
return fPtr;
}
thanks for replying to me

Nov 20 '05 #3
if I use **fPtr insted of *fPtr I get a seg fault

Nov 20 '05 #4
"sulays" <ss**********@yahoo.com> writes:
I need to insert and sort in a link list


Ok, well, good luck with that.

Don't expect much help unless you post an actual question and make
some effort to do it yourself.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 20 '05 #5
please leave some context in your post (as I have)

in general when posting to comp.lang.c you should post a short
*complete* example
that illustrates your problem. I am left trying to gues what the
missing bits of your
program are.
sulays wrote:
in getting an infinite loop dont know why?
where is it looping? The easy way to answer this question is to use a
debugger or
put diagnostic print statements in your program.
this is in main
while(!feof(fpA))
bad idea

the usual C idiom is
while (fgets() != NULL)

lookup fgets() in your textbook for its parameters and semantics

{
readingaemployeedata(&fpA,lastn,firstn,midini,&emp id,title,balance);
some comments would be nice...
if(feof(fpA))
break;
tempPtr =
creatingaemployeedata(lastn,firstn,midini,empid,ti tle,balance);
while(tempPtr != NULL)
I havn't fully analysed your program (I can't because you didn't post
all of it...) but
this loop only exits if tempPtr is NULL. Your loop never modifies
tempPtr. I'm
assuming tempPtr isn't a global.
{
add a diagnostic to confirm this
printf ("tempPtr=%p\n", (void*)tempPtr);
prinheader();
firstemployeePtr = inserting(firstemployeePtr,tempPtr);
printing(firstemployeePtr);
}

function

EIS* inserting(EIS *fPtr,EIS *tempPtr)
{
EIS *prev = NULL;
EIS *curr = NULL;

if(fPtr == NULL)
return tempPtr;

curr = prev = fPtr;
I think it would help if you explained what you are trying to do here.
It would probably
help you as well.

while(curr != NULL)
{
if(strcmp(tempPtr->lastname,curr->lastname) > ZEROI)
{
tempPtr->nextnode = curr;
if(curr == prev)
return tempPtr;
else
prev->nextnode = tempPtr;
return fPtr;
}
else
{
prev = curr;
curr = curr->nextnode;
}
}
prev->nextnode = tempPtr;
return fPtr;
}
thanks for replying to me

--
Nick Keighley

Testing can show the presense of bugs, but not their absence.
-- Dijkstra

Nov 20 '05 #6
sulays wrote:

if I use **fPtr insted of *fPtr I get a seg fault


Post something that I can compile.
If you feel that your program is too large to post,
create a smaller version that exhibits the same problem.

--
pete
Nov 20 '05 #7
Im trying create a link list by accepting initial input from a file
<that part of my program is working ok>
the link list must be maintained in increasing alphabetical order base
on the employee's last name
employees with the same last name I need to listed in alphabetical
order based on the first name and if the have the same last name and
first name need to listed in ascending order based on employee id

trying to do the last name for now and see how it works

EIS* inserting(EIS *fPtr,EIS *tempPtr)
{
EIS *prev = NULL;
EIS *curr = NULL;

if(fPtr == NULL)< this is checking if the list is empty>
return tempPtr;

curr = prev = fPtr;<this is setting the other pointers to the first
node>
tempPtr->nextnode = curr; <this one is for the second node>
while(curr != NULL)
{
if(strcmp(tempPtr->lastname,curr->lastname) > ZEROI)
{
if(curr == prev)
return tempPtr;
else
prev->nextnode = tempPtr;
return fPtr;
}
else
{
prev = curr;
curr = curr->nextnode;
}
}
prev->nextnode = tempPtr;
return fPtr;
}

I dont know why is not working

Nov 20 '05 #8
yes is long and I dont know how to make small version think that
everything is necesary for the program but if you want I can
post the whole thing

Nov 20 '05 #9
LEAVE SOME CONTEXT IN YOUR POSTS!!

that is, please leave in the text of the part of the message you are
replying to.
My replies to your posts do this.

sulays wrote:
yes is long and I dont know how to make small version think that
everything is necesary for the program but if you want I can
post the whole thing


try a simpler problem. Try just building and printing a linked list for
instance.
int main (void)
{
List list;

insert (&list, "red"); /* add an item to the end of the list*/
insert (&list, "blue");
insert (&list, "green");

print (&list);

return 0;
}

this is the way to write a complicated program. Break it into simpler
steps
and solve the steps. When you have a simple program working then add
an extra feature. For instance you could modify insert to insert in the
correct
order,
--
Nick Keighley

Nov 20 '05 #10
like this? I dont know what you want i need hel with the inserting, is
only for last name for now but I need first name and mid ini and id
now i'm getting the first input to print but it stop
int main()
{
List list;
List temp;

while(!feof(fpA))
{
readingaemployeedata(fpA);
if(feof(fpA))
break;
temp = creatingaemployeedata();
while(temp != NULL)
{
list = inserting(list,temp);
printing(list);
}
setptrzero(list);
return 0;
}
}

List* inserting(EIS *list,EIS *temp)
{
List *prev = NULL;
List *curr = NULL;

if(list == NULL)
{
return temp;
}
else
{
curr = prev = list;
temp->next = curr;

while(curr != NULL)
{
if(strcmp(temp->lastname,curr->lastname) > ZEROI)
{
if(curr == prev)
return temp;
else
prev->next = temp;
return list;
}
else
{
prev = curr;
curr = curr->next;
}
}
prev->next = temp;
return list;
}
}

Nov 20 '05 #11
"sulays" <ss**********@yahoo.com> writes:
I need to insert and sort in a link list


I'd recommend a merge sort.
--
"Some programming practices beg for errors;
this one is like calling an 800 number
and having errors delivered to your door."
--Steve McConnell
Nov 20 '05 #12
how do i do that?

Nov 20 '05 #13
sulays wrote
(in article
<11*********************@z14g2000cwz.googlegroups. com>):
how do i do that?


Hint 1: Continuing to snip all relevant context from your posts
is going to piss everyone off.

Hint 2: Continuing to demonstrate zero self-effort at solving
your problems is going to piss everyone off.

Hint 3: We don't do your homework for you here, unless you post
contact information for your professor so we can contact him
directly with a solution.

--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Nov 20 '05 #14
I posted what I have I just wanted to know what was wrong with it
because I can't see it being trying everything and stil not working
instead getting really confuse here with all the hints thanks anyway

Nov 20 '05 #15
On 20 Nov 2005 11:50:52 -0800, in comp.lang.c , "sulays"
<ss**********@yahoo.com> wrote:
I posted what I have I just wanted to know what was wrong with it
because I can't see it being trying everything and stil not working
instead getting really confuse here with all the hints thanks anyway


Didn't someone just say to you:

Hint 1: Continuing to snip all relevant context from your posts
is going to piss everyone off.

Hint 2: Continuing to demonstrate zero self-effort at solving
your problems is going to piss everyone off.

Hint 3: We don't do your homework for you here, unless you post
contact information for your professor so we can contact him
directly with a solution.

--
Please quote enough of the previous message for context. To do so from
Google, click "show options" and use the Reply shown in the expanded
header.

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 20 '05 #16
sulays said:
like this? I dont know what you want i need hel with the inserting, is
only for last name for now but I need first name and mid ini and id
now i'm getting the first input to print but it stop


Thanks for showing your code. I compiled the code you posted, and here's the
compiler's output for you to study:

gcc -W -Wall -ansi -pedantic -O2 -g -pg -c -o foo.o foo.c
foo.c: In function `main':
foo.c:3: `List' undeclared (first use in this function)
foo.c:3: (Each undeclared identifier is reported only once
foo.c:3: for each function it appears in.)
foo.c:3: parse error before `list'
foo.c:6: warning: implicit declaration of function `feof'
foo.c:6: `fpA' undeclared (first use in this function)
foo.c:8: warning: implicit declaration of function `readingaemployeedata'
foo.c:11: `temp' undeclared (first use in this function)
foo.c:11: warning: implicit declaration of function `creatingaemployeedata'
foo.c:12: `NULL' undeclared (first use in this function)
foo.c:14: `list' undeclared (first use in this function)
foo.c:14: warning: implicit declaration of function `inserting'
foo.c:15: warning: implicit declaration of function `printing'
foo.c:17: warning: implicit declaration of function `setptrzero'
foo.c:20: warning: control reaches end of non-void function
foo.c: At top level:
foo.c:22: parse error before `*'
foo.c:22: parse error before `*'
foo.c:23: warning: return-type defaults to `int'
foo.c:23: warning: type mismatch with previous implicit declaration
foo.c:14: warning: previous implicit declaration of `inserting'
foo.c:23: warning: `inserting' was previously implicitly declared to return
`int'
foo.c: In function `inserting':
foo.c:24: `List' undeclared (first use in this function)
foo.c:24: `prev' undeclared (first use in this function)
foo.c:24: `NULL' undeclared (first use in this function)
foo.c:25: `curr' undeclared (first use in this function)
foo.c:27: `list' undeclared (first use in this function)
foo.c:29: `temp' undeclared (first use in this function)
foo.c:38: `ZEROI' undeclared (first use in this function)
foo.c:55: warning: control reaches end of non-void function
make: *** [foo.o] Error 1

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 20 '05 #17
thanks

Nov 20 '05 #18
sulays wrote
(in article
<11**********************@g49g2000cwa.googlegroups .com>):
I posted what I have I just wanted to know what was wrong with it
because I can't see it being trying everything and stil not working
instead getting really confuse here with all the hints thanks anyway


Hint 4: Replace your ROM with RAM.
--
Randy Howard (2reply remove FOOBAR)
"The power of accurate observation is called cynicism by those
who have not got it." - George Bernard Shaw

Nov 20 '05 #19
"sulays" <ss**********@yahoo.com> writes:
I posted what I have I just wanted to know what was wrong with it
because I can't see it being trying everything and stil not working
instead getting really confuse here with all the hints thanks anyway


If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.

This will automatically quote the previous message and add an
attribution line. The result will be similar to this followup, where
I've quoted what you wrote and indicated that you were the one who
wrote it.

We can't necessarily see the article to which you're replying. Each
followup needs to provide enough context so it can be read on its own.
(That doesn't mean you need to quote the entire article, just enough
for your followup to make sense.)

We have tried to tell you this several times, and you have
consistently failed to follow our advice. Please correct this;
otherwise, we'll probably give up on trying to help you.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 21 '05 #20
Keith Thompson said:
We have tried to tell you this several times, and you have
consistently failed to follow our advice. Please correct this;
otherwise, we'll probably give up on trying to help you.


Too late.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 21 '05 #21
sulays wrote:
I posted what I have I just wanted to know what was wrong with it
because I can't see it being trying everything and stil not working
instead getting really confuse here with all the hints thanks anyway

one last try...

You have been given several items of advice by myself and other people
and seem incapable of following simple advice. Please read this post
carefully and try to follow the advice I give,

1. always leave some context. This means you quote the post (or parts
of it) you are replying to. By this time I have no idea what program
you
are talking about.

2. if posting code you have a problem with then post SHORT,
COMPLETE examples.The code should compile. You have consistently
ommitted important data structures and functions from your posts.

3. if your code is too long to post then post a shorter version that
illustrates your problem. For instance I suggested you write a simpler
program that built and printed a list. We would then know if you
understood the basics of linkedlists and were capable of writing a
simple program.

4. you posted code saying it had an infinite loop. I suggested you
added diagnostic code. I suggested a possible problem. Did this solve
your problem? If so why are you still posting?

5. the code you posted lacks comments and uses poor choices in the
selection of identifier names. I would give examples but you snipped
the context...

I begin to wonder if you have some of the desirable charcter traits
that will enable you to program successfully. You need to listen when
people explain things. You need to break complex problems into
simpler ones. You need to think clearly. You need to communicate
clearly. Learn these things and you will become a better person.

In a sense we should be grateful to you for illustrating in multiple
ways
why leaving context in your post is a good idea.
--
Nick Keighley (Before Coffee)

Nov 21 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.