Thread: 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. |
|
From: Vale G. <val...@at...> - 2005-01-30 17:52:51
|
> 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> <<< Is that line 2? . [snip] . exit(1); } <<< Probably line 70. > 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 > How can a error that is supposed to occur at the end of the file occur in line 2 anyway? Strictly speaking, it's a warning. An error will prevent it from compiling but it compiles and runs. Some errors and warnings within functions are reported with the line number of the end of the function or the beginning of the function. The compiler sometimes cannot determine where the actual problem lies. Perhaps the problem actually lies on line 2 (and in stdlib.h) as indicated. Perhaps the compiler is confused by other warnings which this program produces. Turning on all warnings with "-W -Wall -Wunused -pedantic" compiler options and I get: C:/WINDOWS/Desktop/states.c: In function `main': C:/WINDOWS/Desktop/states.c:12: warning: implicit declaration of function `strcmp' C:/WINDOWS/Desktop/states.c:16: warning: implicit declaration of function `toupper' C:/WINDOWS/Desktop/states.c:10: warning: unused variable `st' C:/WINDOWS/Desktop/states.c:10: warning: unused variable `string' C:/WINDOWS/Desktop/states.c: In function `findstate': C:/WINDOWS/Desktop/states.c:31: warning: implicit declaration of function `strcpy' C:/WINDOWS/Desktop/states.c:31: warning: pointer targets in passing arg 1 of `strcpy' differ in signedness C:/WINDOWS/Desktop/states.c:32: warning: implicit declaration of function `strcat' C:/WINDOWS/Desktop/states.c:32: warning: pointer targets in passing arg 1 of `strcat' differ in signedness C:/WINDOWS/Desktop/states.c:33: warning: pointer targets in passing arg 1 of `strcat' differ in signedness C:/WINDOWS/Desktop/states.c:34: warning: pointer targets in passing arg 1 of `strcat' differ in signedness C:/WINDOWS/Desktop/states.c:35: warning: pointer targets in passing arg 1 of `strcat' differ in signedness C:/WINDOWS/Desktop/states.c:36: warning: pointer targets in passing arg 1 of `strcat' differ in signedness If you fix those warnings you might also correct the missing newline warning. Also, in Tools > Editor Options > General, make sure that "Keep Trailing Spaces" is unchecked. You have eight lines with trailing spaces. They probably aren't causing any problems but there's no use in cluttering up your code. Chuck |
|
From: Per W. <pw...@ia...> - 2005-01-31 00:31:52
|
I would say that your error is on line 70. You have made a lot of new lines in the end. However, are you sure that the last line is empty, and doesn't contain any spaces or tabs? Alas, my mail program can't show mey white space at end of lines. /Per W On Sun, 30 Jan 2005 ml...@gf... wrote: > Here is an example with a program I have written. It is a one-file program, and it's relatively small: > 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 > > 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. |
|
From: Gerson L. <ja...@ya...> - 2005-02-01 18:30:06
|
Hello everybody!. Iv'e seen the messages for this issue. I think, that there is no problem at all with the code shown before, but, lokk at this: "2 C:\Dev-Cpp\Templates\states.c:70 [Warning] no newline at end of file 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." there is an #include in the line 2, isn't it? Remember what #include <filenme> does: it is like copy-pasting the contens of "filename" as it is, into your code. I mean, the error may be in <stdlib.h> or the file that you're including. Try to change the line in wich the include apears, move it to line 1, 3 ... etc. If the warnig seems to be always in the same line of the include, then the problem is in the included file, so find the file, make a backup copy and put the new-line at the end of the original.(be careful of modifying only that!), save, and compile... I've had similar problems, an that has been a solution. But, I don't give any warranty. Please tell me( all of us, really), how do you finally resolve it... Hoping to be helpful: Gerson. --------------------------------- |