Last active
          October 19, 2017 13:19 
        
      - 
      
- 
        Save rdeioris/a06ca5c82e64719c54122e00a61b5c4c to your computer and use it in GitHub Desktop. 
    First C program
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #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