KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am thinking of something like: #include <stdio.h> #include <conio.h> #include <stdlib.h> int main(void) { //test pointer to string char s[50]; char *ptr=s; printf("\nEnter string (s): "); fgets(s, 50, stdin); printf("S: %s\nPTR: %s\n", s, *ptr); system("PAUSE"); return 0; } Or should I use a for loop with *(s+i) and the format specifier %c? Is that the only possible way to print a string through a pointer and a simple printf? Update: The printf operates with the adress of the first element of the array so when I use *ptr I actually operate with the first element and not it's adress. Thanks.
Tags (comma-separated)
Save Edits
Cancel