#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;ctype.h%26gt;
int main(int n,char*str[])
{
char*line[128];
FILE *fp=0;
if (str[1])
fp=fp=fopen (str[1],"r");
else
printf("enter the file you want listed on command line");
if
(fp)
{
while(fgets(fp,line,sizeof line))
print("%s\n",line);
}
}
else
{
printf("bad filename.");
}
}
}
{
char c;
FILE * fp=0;
if (str[1])
fp=fopen(str[1],"r");
else
*ERROR*
if (fp)
{
while (!feof (fp))
{
c=fgetc(fp);
}
printf("%c",c);
}
}
else
{
*ERROR*
}
my errors are
Need help with c?
This indicates that you have given fgets the wrong arguments.
The prototype of fgets is
char * fgets ( char * str, int num, FILE * stream );
so move fp to the end of the parameter list.
Next you have not made a string but a pointer to a string array which isn't the same thing. You should have written
char line[128];
Then it appears that your braces are not nested correctly and you have rather more than are required.
Once you fix these it may work. In real life programming you need to understand what the compiler is saying when it puts up errors.
Reply:#define _CRT_SECURE_NO_WARNINGS
#include %26lt;stdio.h%26gt;
#include %26lt;stdlib.h%26gt;
#include %26lt;ctype.h%26gt;
int main(int n,char*str[])
{
{
char line[128];
FILE *fp=0;
if (str[1])
fp=fp=fopen (str[1],"r");
else
printf("enter the file you want listed on command line");
if(fp)
{
while(fgets(line,sizeof line,fp))
printf("%s\n",line);
}
else
{
printf("bad filename.");
}
}
{
char c;
FILE * fp=0;
if (str[1])
fp=fopen(str[1],"r");
else
printf("*ERROR*");
if (fp)
{
while (!feof (fp))
{
c=fgetc(fp);
}
printf("%c",c);
}
else
{
printf("*ERROR*");
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment