Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int input( int array[500][500], int *x0, int *y0 ) {
- int x = 0;
- int y = 0;
- int err = 0;
- char c;
- printf("Size:\n");
- if ( scanf("%d %d%c", x0, y0, &c)!=3 || *x0<=0 || *y0<=0 || *x0>500 || *y0>500 || c!='\n' ) {
- printf("Invalid input.\n");
- return 0;
- }
- while ( y < *y0 ) {
- x = 0;
- while ( x < *x0 ) {
- c = fgetc(stdin);
- if ( (x== *x0 - 1) && (c!='\n') ) { //after enough inputs, newline must follow
- err = 1;
- break;
- }
- switch(c) { // only these three chars are accepted
- case 'o':
- array[y][x] = 1;
- break;
- case '.':
- array[y][x] = 0;
- break;
- case '!':
- array[y][x] = 2;
- break;
- case '\n': //if we have entered less chars than size
- if (x < *x0 - 1)
- err = 1;
- break;
- default:
- err = 1;
- break;
- }
- x++;
- }
- if (x > *x0)
- err=1;
- y++;
- }
- if (y!=*y0)
- err=1;
- if (err==1) {
- printf("Invalid input.\n");
- return 0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment