C Program to Reverse Strings Input from User
#include<stdio.h> #include<string.h>
int main() { char arr[80][80]; // 2D char array to store the strings char a; // To store the newline character int i; // Loop variable
// Taking input from the user until newline character is encountered
for(i=0;a!='
';++i) { scanf("%s%c",&arr[i],&a); // %c is used to capture the newline character }
// Printing the strings in reverse order
for(i--;i>=0;i--)
{
printf("%s",arr[i]); // Printing the string
if(i!=0)
printf(" "); // Adding a space between the strings
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/p4no 著作权归作者所有。请勿转载和采集!