c_winter_2019/printing_strings.c

39 lines
677 B
C
Raw Normal View History

2020-01-31 14:49:37 +01:00
#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);
}