![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to read values that are passed to the shell function in ksh. | prashant43 | Shell Programming and Scripting | 2 | 01-22-2008 11:21 AM |
| fscanf | abey | High Level Programming | 4 | 02-14-2006 09:29 AM |
| read function | rajashekaran | UNIX for Dummies Questions & Answers | 1 | 04-12-2002 05:55 PM |
| fscanf() | j_t_kim | High Level Programming | 3 | 04-03-2002 08:59 AM |
| fscanf() | j_t_kim | High Level Programming | 1 | 03-15-2002 11:52 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
read a file wich fscanf() in a function
I use fopen, fscanf, fclose to read a file. It can work well. since many files should be read, a function is created with the same code. But in the function, fscanf can not work well.
for example, the first line of the the file is: > filename but the fscanf will give: 207/23/eee/34 it appears to be a random address Is it due to the function stack? Wish our guru to give some guidance thanks |
|
||||
|
This will read a text file Code:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv)
{
if(argc > 1)
{
char tmp[256]={0x0};
FILE *in=fopen(argv[1], "r");
if(in==NULL)
{
perror("Error opening input file")
exit(1);
}
while (fgets(tmp, sizeof(tmp), in)!=NULL) printf("%s", tmp);
if(feof(in) )
{
fclose(in);
return 0;
}
perror("File I/O error");
}
return 1;
}
regardless of format - fscanf is designed for reading in a file with a known format. Without your code we cannot tell what is wrong. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|