39 lines
677 B
C
39 lines
677 B
C
|
#include <stdio.h>
|
||
|
|
||
|
/**
|
||
|
* print a given string char by char using pointer arithmetic
|
||
|
* @param str string to print
|
||
|
*/
|
||
|
void print_string(char *str);
|
||
|
|
||
|
/**
|
||
|
* similar to print_string but using recursion
|
||
|
* @param str string to print
|
||
|
*/
|
||
|
void print_string_rec(char *str);
|
||
|
|
||
|
int main(int argc, char **argv) {
|
||
|
for (int i = 0; i < argc; ++i) {
|
||
|
print_string(*argv);
|
||
|
argv++;
|
||
|
putchar('\n');
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void print_string(char *str) {
|
||
|
while(*str != '\0') {
|
||
|
putchar(*str);
|
||
|
str++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void print_string_rec(char *str) {
|
||
|
if (*str == '\0') {
|
||
|
return;
|
||
|
}
|
||
|
putchar(*str);
|
||
|
++str;
|
||
|
print_string_rec(str);
|
||
|
}
|