I am a C beginner who has been assigned to write a program that uses pointers to reverse a message. I am having trouble getting the for loop that reads the characters to break after it reads a newline and I don't want to use a while loop.
Below is my code:
#include <stdio.h>
#include <string.h>
int main(){
//declare string
char reverse[100];
//declare pointer
char *first;
//set pointer to point to first element of array
first = &reverse[0];
//get chars until end of input
printf("Enter a message:");
for (first = reverse; *first != '\n'; first++){
scanf("%c", first);
printf("%c", *first);
}
//reverse chars one by one
printf("Reversal: ");
for (first; first >= reverse; first--){
printf("%c", *first);
}
printf("\n");
return 0;
}
Thank you! Any help is appreciated :)