home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!leus
- From: leus@aix.rpi.edu (Sheua-Wan Leu)
- Subject: fgetc problem
- Message-ID: <3!22=4a@rpi.edu>
- Keywords: fgetc
- Nntp-Posting-Host: aix.rpi.edu
- Date: Tue, 29 Dec 1992 21:27:40 GMT
- Lines: 82
-
-
- I want the following program to read data from an input.pts file.For the
- first 4 sets data, it works fine, but it print out the last data twice.
- If I delete the first line in input.pts file(content 1), it program does
- not work at all.
-
- Is there anyone can give me some sort of hint ? Except the fgetc, is there
- other function I can use ?
-
- Sheua-wan @rpi
- /************************* program *******************************/
-
- #include <stdio.h>
- #include <stdlib.h>
- struct node{
- int id;
- int x;
- int y;
- struct node *next;
- };
- typedef struct node NODE;
-
- void get();
- void newnode();
- NODE *head;
- main()
- {
- NODE input;
-
- FILE *ifp;
- int c;
- int i,xx;
-
- head=NULL;
- ifp=fopen("input.pts","r");
- while((c=fgetc(ifp)) !=EOF){
- fscanf(ifp,"%d %d %d",&input.id, &input.x,&input.y);
- printf("num\n");
- newnode(input);
- }
- for(i=0;i<10;i++){
- printf("input search node :");
- printf("\n");
- scanf("%d",&xx);
- get(xx);
- }
- }
- void newnode(NODE data)
- {
- NODE *temp;
- temp=(NODE *)malloc(sizeof(NODE));
- temp->x=data.x;
- temp->y=data.y;
- temp->id=data.id;
- if(head==NULL)
- {
- temp->next=NULL;
- head=temp;
- }
- else
- {
- temp->next=head;
- head=temp;
- }
- }
-
- void get(int find)
- {
- NODE *first,*curr;
- first=head;
- for(curr=first;curr !=NULL; curr=curr->next)
- if(curr->id==find)
- printf("got it out=%d %d %d\n",curr->id,curr->x,curr->y);
- }
- /************************* data file ***************/
- 1
- 1 100 250
- 2 50 10
- 3 50 50
- 4 1 100
- 5 2 300
-
-