Advertisement
Mazamin

Simulazione 0506

Jun 5th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. /*
  2.  * File:   main.c
  3.  * Author: Gerardo Cicalese
  4.  *
  5.  * Created on 5 giugno 2019, 10.42
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12. #include "simlib.h"
  13.  
  14. /*
  15.  *
  16.  */
  17.  
  18. void myerror(char *, int);
  19.  
  20. int main(int argc, char** argv) {
  21.     int v_len, pos, j;
  22.     char c;
  23.    
  24.     if(3!=argc)
  25.         myerror("argc", 6);
  26.    
  27.     for(int i=0;i<strlen(argv[1]);++i)
  28.         if(!isalpha(argv[1][i]))
  29.             myerror("stringa 1", 1);
  30.    
  31.     for(int i=0;i<strlen(argv[2]);++i)
  32.         if(!isdigit(argv[2][i]))
  33.             myerror("stringa 2", 2);
  34.    
  35.     sscanf(argv[2], "%d", &v_len);
  36.    
  37.     if(v_len<=((strlen(argv[1])/2)+1))
  38.         myerror("out of memory", 7);
  39.    
  40.     char array[v_len];
  41.    
  42.     if(0==pulisci(array, v_len))
  43.         myerror("pulisci", 3);
  44.    
  45.     printf("%s\n", array);
  46.    
  47.     for(j=0;j<(strlen(argv[1])/2)+1;j++)
  48.         array[j]=toupper(argv[1][2*j]);
  49.  
  50.     printf("%s\n", array);
  51.    
  52.     puts("Dammi un carattere");
  53.     scanf("%c", &c);
  54.     pos=trova(array, v_len, toupper(c));
  55.    
  56.     if(0==pos)
  57.         myerror("trova", 4);
  58.    
  59.     printf("POSIZIONE: %d\n", pos);
  60.    
  61.     if(0==riempi(array, v_len, toupper(c)))
  62.         myerror("riempi", 5);
  63.    
  64.     printf("%s\n", array);
  65.     return 0;
  66. }
  67.  
  68. void myerror(char * str, int n){
  69.     printf("ERRORE: %s\n", str);
  70.     exit(n);
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement