gcc is noughty on my c code.
Hello all..
I am making a code that prints random characters from the template. Thing is.. I make a printf() and specify template[ch]. when 'template' is a char and 'ch' is an int to specify where in the char it will print. But gcc does not look at template. it looks at 'ch' and thought it was int. I don't know who's fault this is (gcc or me). Here is the code: Code:
#include <stdio.h> |
Quote:
I am telling you that you have type mismatch, and it's your challenge to understand why/where. |
"%s" expects a pointer to a null-delimited string of characters.
But template[ch] is not that: it's a single (integer...) value consisting of one character taken from an array. No wonder "C" is confused. The ASCII equivalent of, say, the letter "q", is probably not a valid pointer! |
It is even worse than that. The value of template[ch] will always be the terminating null byte of the initializing literal string. So dereferencing it should result in a segmentation fault.
--- rod. |
All times are GMT -5. The time now is 10:56 PM. |