I could not get the %s strinf function to work for the elementary C tutorial that comes with your compiler. For instance
include <stdio.h>
include <string.h>
main ()
{
int a=3,b=-5;
double e=7.8945783;
char eh='h';
printf ("C standard I/O file is included\n");
printf ("Hello world!");
printf("\n");
printf("%s", eh) ;
/ printf("%-25s, Hello")/
printf ("%-10d %-10d",a,b);
printf ("%-#10d %#-12.5g",a,e);
system("PAUSE");
}
compiles without error but when I execute (run ) the code I get an error report saying that the exe code has an error and whether I should send error reprot to Microsoft. Could you rectify this ?
It died at the printf("%s", eh) ; statement.
Please help Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The variable eh is a character not a string so %s is an inappropriate format specifier. The compiler option -Wformat will cause a warning to be generated for that code. I suggest that in fact you habitually use -Wall -Wformat -Werror, then the code would not even have compiled - whch is exactly what you want to happen when code contains errors.
Note that the "C tutorial that comes with your compiler" is a pile of doo. It is very old and very flawed (and was even when it was new). Get your education from elsewhere. Besides would you not rather be learning C++? ;-) Few are prefect, but you could do worse than http://www.cplusplus.com/doc/tutorial/
Note also that it is not "our" compiler. This is a user community, and Dev-C++ is not a compiler in any case, it is an IDE for the GNU compiler. The version of GCC that you are using comes from www.mingw.org.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I could not get the %s strinf function to work for the elementary C tutorial that comes with your compiler. For instance
include <stdio.h>
include <string.h>
main ()
{
int a=3,b=-5;
double e=7.8945783;
char eh='h';
printf ("C standard I/O file is included\n");
printf ("Hello world!");
printf("\n");
printf("%s", eh) ;
/ printf("%-25s, Hello")/
printf ("%-10d %-10d",a,b);
printf ("%-#10d %#-12.5g",a,e);
system("PAUSE");
}
compiles without error but when I execute (run ) the code I get an error report saying that the exe code has an error and whether I should send error reprot to Microsoft. Could you rectify this ?
It died at the printf("%s", eh) ; statement.
Please help Chris
The variable eh is a character not a string so %s is an inappropriate format specifier. The compiler option -Wformat will cause a warning to be generated for that code. I suggest that in fact you habitually use -Wall -Wformat -Werror, then the code would not even have compiled - whch is exactly what you want to happen when code contains errors.
Note that the "C tutorial that comes with your compiler" is a pile of doo. It is very old and very flawed (and was even when it was new). Get your education from elsewhere. Besides would you not rather be learning C++? ;-) Few are prefect, but you could do worse than http://www.cplusplus.com/doc/tutorial/
Note also that it is not "our" compiler. This is a user community, and Dev-C++ is not a compiler in any case, it is an IDE for the GNU compiler. The version of GCC that you are using comes from www.mingw.org.