Fw: [Dev-C++] No Newline At End of File
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <ml...@gf...> - 2005-01-30 15:13:38
|
Here is an example with a program I have written. It is a one-file =
program, and it's relatively small:
-------------------------------------------------------------------------=
-------
#include <stdio.h>
#include <stdlib.h>
void restore(void);
int findstate(unsigned char in1,unsigned char in2);
void usagemes(char **argv);
void colorstate(FILE *map,int loc,unsigned char rval,unsigned char =
gval,unsigned char bval);
int main(int argc, char *argv[])
{
FILE *map;
unsigned char rval,gval,bval,st[104],in1,in2,*string;
if (argc=3D=3D1) usagemes(argv);
if (!strcmp(argv[argc-1],"/clear")) restore();
map=3Dfopen("c:/windows/desktop/usmap_5.gif","r+b");
if (argc>4)
{
in1=3Dtoupper(argv[1][0]);
in2=3Dtoupper(argv[1][1]);
rval=3Datoi(argv[2]);
gval=3Datoi(argv[3]);
bval=3Datoi(argv[4]);
} =20
colorstate(map,findstate(in1,in2),rval,gval,bval);
fclose(map); =20
return 0;
}
/************************************************************************=
******/
int findstate(unsigned char in1,unsigned char in2)
{
int loc;
unsigned char st[104];
strcpy(st,"BGALMSPAHINMVALADEOH");
strcat(st,"TNARIAMINEWINCSCMTAZ");
strcat(st,"COUTILORNVWYGAKSCAMN");
strcat(st,"NDMOMDNYOKAKTXWAKYIN");
strcat(st,"MESDNHWVVTMANJFLIDCT");
strcat(st,"RIDC");
for(loc=3D0;loc<104;loc+=3D2)
{
if (st[loc]=3D=3Din1 && st[loc+1]=3D=3Din2) break;
}
if (loc>103)
{
fprintf(stderr,"\"%c%c\" is not a valid state code\n, returning =
background",in1,in2);
loc=3D0; =20
} =20
return (loc/2);
}
/************************************************************************=
******/
void colorstate(FILE *map,int loc,unsigned char rval,unsigned char =
gval,unsigned char bval)
{
fseek(map,13+(loc*3),SEEK_SET); =20
fwrite(&rval,1,1,map);
fwrite(&gval,1,1,map);
fwrite(&bval,1,1,map); =20
} =20
/************************************************************************=
******/
void restore(void)
{
printf("Restoring map to blank...");
system("copy c:\\windows\\desktop\\usmap.gif =
c:\\windows\\desktop\\usmap_5.gif");
}
/************************************************************************=
******/
void usagemes(char **argv)
{
fprintf(stderr,"Usage: %s statecode r_val g_val b_val =
[/clear]\n",argv[0]);
fprintf(stderr,"statecode =3D The two-letter postal code of a US =
state or DC\n");
fprintf(stderr,"r_val, g_val, b_val =3D color values from 0-255\n"); =
=20
fprintf(stderr,"/clear =3D copies the original blank map to the =
output file, clearing it\n");
exit(1);
}
-------------------------------------------------------------------------=
-------
No matter how many times I hit the enter key at the end of this file, I =
keep getting this message:
2 C:\Dev-Cpp\Templates\states.c:70 [Warning] no newline at end of file=20
How can a error that is supposed to occur at the end of the file occur =
in line 2 anyway? If anyone has any idea what is up here, please tell =
me. |