Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.c
- * Author: Gerardo Cicalese
- *
- * Created on 5 giugno 2019, 10.42
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include "simlib.h"
- /*
- *
- */
- void myerror(char *, int);
- int main(int argc, char** argv) {
- int v_len, pos, j;
- char c;
- if(3!=argc)
- myerror("argc", 6);
- for(int i=0;i<strlen(argv[1]);++i)
- if(!isalpha(argv[1][i]))
- myerror("stringa 1", 1);
- for(int i=0;i<strlen(argv[2]);++i)
- if(!isdigit(argv[2][i]))
- myerror("stringa 2", 2);
- sscanf(argv[2], "%d", &v_len);
- if(v_len<=((strlen(argv[1])/2)+1))
- myerror("out of memory", 7);
- char array[v_len];
- if(0==pulisci(array, v_len))
- myerror("pulisci", 3);
- printf("%s\n", array);
- for(j=0;j<(strlen(argv[1])/2)+1;j++)
- array[j]=toupper(argv[1][2*j]);
- printf("%s\n", array);
- puts("Dammi un carattere");
- scanf("%c", &c);
- pos=trova(array, v_len, toupper(c));
- if(0==pos)
- myerror("trova", 4);
- printf("POSIZIONE: %d\n", pos);
- if(0==riempi(array, v_len, toupper(c)))
- myerror("riempi", 5);
- printf("%s\n", array);
- return 0;
- }
- void myerror(char * str, int n){
- printf("ERRORE: %s\n", str);
- exit(n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement