Help with File operations
Dear All,
My task is as follows:-
1. I have to open file :CAN.c
2. find preprocessor directive
3. If preprocessor directive is Capital then i have to convert it into Lower
Ex:- #include<CAN.c>---------------->#include<can.c>
4. write it into other file
so for i have done as follows:-
Code:
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char **argv)
{
const int max=1024;
int r=0,i;
FILE *in,*out;
in=fopen("C:\\Documents and Settings\\syg4kor\\Desktop\\Perl_Programming\\CAN.c","rb");
out=fopen("C:\\Documents and Settings\\syg4kor\\Desktop\\Perl_Programming\\CAN_CPY.c","wb");
char buff[max+3];
if (argc!=3)
{
r=1;
printf("usage: lower <src> <dest>\n");
}
else if ((in=fopen(argv[1],"rb"))==NULL)
{
r=2;
printf("cannot open input-file!\n");
}
else if ((out=fopen(argv[2],"wb"))==NULL) // Output file will be overwritten when exists !!!
{
r=3;
printf("cannot open output-file!\n");
}
else
{
while (!feof(in))
{
buff[0]=0;
fgets(buff,max,in);
for (i=0;i<max && buff[i]!=NULL && &buff[i]!='\r' && buff[i]!='\n' && (buff[i]==' ' || buff[i]=='\t');i++);
if (buff[i]=='#')
{
for (i=i+1;i<max && buff[i]!=NULL && buff[i]!='\r' && buff[i]!='\n';i++)
{
buff[i]=tolower(buff[i]);
}
}
fputs(buff,out);
}
fclose(out);
}
fclose(in);
return 0;
}
But i am getting following errors in highleghed line:
1. error C2446: '!=' : no conversion from 'int' to 'char *'
2. error C2040: '!=' : 'char *' differs in levels of indirection from 'int'
can anybody help me..actually i am learning C programming using this sight..this sight really very helpfull for learning C..i am thankful to all of you
Thanks manav..i got zero error
Thanks manav it is working...
Quote:
Originally Posted by
manav
Code:
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc,char **argv)
{
const int max=1024;
int r=0,i;
FILE *in,*out;
in=fopen("C:\\Documents and Settings\\syg4kor\\Desktop\\Perl_Programming\\CAN.c","rb");
out=fopen("C:\\Documents and Settings\\syg4kor\\Desktop\\Perl_Programming\\CAN_CPY.c","wb");
char buff[max+3];
if (argc!=3)
{
r=1;
printf("usage: lower <src> <dest>\n");
}
else if ((in=fopen(argv[1],"rb"))==NULL)
{
r=2;
printf("cannot open input-file!\n");
}
else if ((out=fopen(argv[2],"wb"))==NULL) // Output file will be overwritten when exists !!!
{
r=3;
printf("cannot open output-file!\n");
}
else
{
while (!feof(in))
{
buff[0]=0;
fgets(buff,max,in);
for (i=0;i<max && buff[i]!=NULL && &buff[i]!='\r' && buff[i]!='\n' && (buff[i]==' ' || buff[i]=='\t');i++);
if (buff[i]=='#')
{
for (i=i+1;i<max && buff[i]!=NULL && buff[i]!='\r' && buff[i]!='\n';i++)
{
buff[i]=tolower(buff[i]);
}
}
fputs(buff,out);
}
fclose(out);
}
fclose(in);
return 0;
}
Can you catch the errors highlighted in
RED?