Hi all,
Now I'm coding a short program which can get the string from 2 column to 72 column in a file(total 80 column), but the run result is not right, the format of the outfile is not correct as a normal file.
Can anyone kindly tell me where is the question in my program, thanks a lot.
here is my program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//infile means input pli source file,outfile means analysys result
FILE *infile;
FILE *outfile;
//FILE *result;
char msg[80];
char linebuf[73];
char *ptr; //pointer ptr point to thr string linebuf
int counter;
void main(int argc,char * argv[])
{
if (argc < 2)
{
printf("No file specified\n\n");
printf("Usage: cut inputfile-name outputfile-name\n");
exit(1);
}
if ((infile = fopen(argv[1],"r")) == NULL)
{
printf("Can't open %s",argv[1]);
exit(1);
}
if ((outfile = fopen(argv[2],"w")) == NULL)
{
printf("Can't open %s",argv[2]);
exit(1);
}
ptr = NULL;
while(!feof(infile))
{
ptr = linebuf;
if (fgets(msg,81,infile))
{
for (counter = 0;counter < 72;counter++)
{
if (counter == 0)
continue;
else
{
*ptr = msg[counter];
ptr++;
}
}
*ptr = NULL;
fputs(linebuf,outfile);
}
}
fclose(infile);
fclose(outfile);
printf("\nGood job has done\n");
}