Home CPSC 305

String Exercise



To get practice writing C programs, including strings.

Compiling C Programs

To compile a C program on a Linux system, use the gcc command. This command takes a C program as its argument and compiles it to an executable program called, by default, a.out:

$ gcc hello.c
$ ./a.out
Hello World!

If you want the program to be something other than a.out, it can be specified after the -o flag:

$ gcc hello.c -o hello
$ ./hello
Hello World!



For this program you will write a function which reverses a string in place. Recall that passing a string into a function means passing a pointer to a char. After calling the reverse function, the string should be reversed.

You should also write a main function which reads in a string of size up to 100 with scanf, calls your reverse function, and then prints the result with printf.


Sample Run

$ ./reverse
Enter a string: abcd
$ ./reverse
Enter a string: abcde



When you are done, please submit the C code under the assignment in Canvas.

Copyright © 2024 Ian Finlayson | Licensed under a Attribution-NonCommercial 4.0 International License.