strings/ printing strings
Posted: Tue Apr 22, 2003 2:37 pm
in c/c++ you can declare a string:
char str[5]="hello"
and the compiler puts the chars right next to each in memory...
but if you try to print this string to the screen:
char *temp;
*temp=str[zero]; (zero = 0) mega tokyo format messes it up
print(temp);
it will print the first char 'h' and then junk. why does this happen because all the chars should print because they are right next to each other.
----------------------------------------------------------------
char *str="hello"
print(str);
this will print the string correctly. why?
arent the two the same? how would i go about print an array of chars that is declare like: char str[5]="hello"?
char str[5]="hello"
and the compiler puts the chars right next to each in memory...
but if you try to print this string to the screen:
char *temp;
*temp=str[zero]; (zero = 0) mega tokyo format messes it up
print(temp);
it will print the first char 'h' and then junk. why does this happen because all the chars should print because they are right next to each other.
----------------------------------------------------------------
char *str="hello"
print(str);
this will print the string correctly. why?
arent the two the same? how would i go about print an array of chars that is declare like: char str[5]="hello"?