Advertisement
Mazamin

Esercizio Fscanf

Dec 13th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define MAX_LEN 64
  5.  
  6. void reverse_string(char [MAX_LEN], int);
  7.  
  8. main(){
  9.     FILE * fp;
  10.     char string[MAX_LEN];
  11.     ((fp=fopen("testo.txt", "r"))!=NULL)?:(exit(1));
  12.     while(feof(fp)==0){
  13.         fscanf(fp, "%63[a-zA-Z]%*[^a-zA-Z]", string);
  14.         reverse_string(string, strlen(string));
  15.         printf("%s %d\n", string, (int)strlen(string));
  16.     }
  17.     return 0;
  18. }
  19.  
  20. void reverse_string(char str[MAX_LEN], int size){
  21.     int i;
  22.     for(i=0;i<size/2;i++)
  23.         str[i]^=str[size-i-1]^=str[i]^=str[size-i-1];
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement