Hello there !
Noobie here, just joined the community ^_^
Anyways, I have a problem where I'm trying to cycle through memory via pointers to print a string. Here is my code:
Code:
#include <stdio.h>
int main(void){
char word[]="hello there";
int *pword = word;
for(;*pword!='\0';pword++){
printf("%c",*pword);
}
return 0;
}
When compiled, the returning string is "hoe".
Funny thing is, whilst experimenting and trying to find alternate ways to get this done right, using a function to print seems to get the trick done. Here's my code using a function.
Code:
#include <stdio.h>
int main(void){
char word[]="hello there";
print(word);
return 0;
}
void print(char *word){
for(;*word!='\0';word++){
printf("%c",*word);
}
}
This seems to effectively portray what I want
How do I print a string using the same method for(;*pointer!='\0';pointer++) without a function?
Kind regards