/* WSU - CS 3830-0 - Fall 06 - Project 1b Vincenzo Maggio Code */ #include #include int main( int argc, char *argv[] ) { /* buffers here allocation has been made with odd numbers only for program purpose. usually i allocate even rooms */ static char lastName[11]; static char firstName[11]; static char fullName[23]; int i; char c; /* all we need is just 2 parms */ if ( argc != 3 ) { printf("\nExit: -1. Wrong parameters count\n"); return -1; } /* make sure str is null terminated */ memset( lastName, 11, '\0'); memset( firstName, 11, '\0'); memset( fullName, 23, '\0'); /* - let's scan the chars one at time - the count stops at 10 - however each char is indivually checked */ for ( i = 0; i < 10; i++) { c = (char) *( argv[1] + i); /* end of string ? */ if ( c == '\0' ) break; /* what ya talkin about */ if ( ! isalpha( c) && ! isdigit(c) && ! ispunct( c) ) { printf("\nExit: -2. Wrong char\n"); return -2; } lastName[i] = c; } for ( i = 0; i < 10; i++) { c = (char) *( argv[2] + i); /* end of string ? */ if ( c == '\0' ) break; /* what ya talkin about */ if ( ! isalpha( c) && ! isdigit(c) && ! ispunct( c) ) { printf("\nExit: -2. Wrong char\n"); return -2; } firstName[i] = c; } strcat( fullName, lastName); strcat( fullName, ", "); strcat( fullName, firstName); printf("\n lastName: %s\n",lastName); printf(" firstName: %s\n",firstName); printf("\n fullName: %s\n",fullName); if ( strcmp( firstName, argv[2])) printf("\n firstName does NOT MATCH argv[2]\n"); else printf("\n firstName MATCHES argv[2]\n"); return 0; }