Files
ece373-hw/hw1/sample_string_reverse.c
Edith Boles cd07449a48 Add hw1
2026-04-09 00:14:59 -07:00

29 lines
392 B
C

#include <stdio.h>
int main(int argc, char *argv[])
{
char buf[50];
printf("Input string to reverse: ");
fgets(buf, 50, stdin);
int max = 0;
char *c = buf;
while (*c++)
max++;
max--;
buf[max] = '\0';
max--;
for (int i = 0; i < max - i; i++) {
int top = max - i;
char temp = buf[top];
buf[top] = buf[i];
buf[i] = temp;
}
printf("Reversed: %s\n", buf);
return 0;
}