Skip to content

Instantly share code, notes, and snippets.

@rdeioris
Last active October 19, 2017 13:19
Show Gist options
  • Save rdeioris/a06ca5c82e64719c54122e00a61b5c4c to your computer and use it in GitHub Desktop.
Save rdeioris/a06ca5c82e64719c54122e00a61b5c4c to your computer and use it in GitHub Desktop.
First C program
#include <stdio.h>
#include <stdlib.h>
int aiv_strlen(char *str)
{
// 100 100
char *original_ptr = str;
while(*str) {
str++;
}
return str - original_ptr - 1;
/*int counter = 0;
while(*str){
str++;
counter++;
}
return counter;*/
/*
while(*str++);
return str - original_ptr - 2;
*/
}
int main(int argc, char *argv[])
{
char player_name[99];
if (!fgets(player_name, 99, stdin)) {
fprintf(stderr, "mortacci tua\n");
return -1;
}
int len = aiv_strlen(player_name);
char *reversed = malloc(len + 1);
for(int i=0;i<=len;i++) {
reversed[len-i] = player_name[i];
}
fprintf(stdout, "Hello: %d %s\n", len, reversed);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment