char - Returning wrong file pointer -
for reason when send argv gets sends wrong file pointer. example if send string argv of getty.txt sends shakes file pointer , if send genesis.txt char array sends getty.txt. how send right file pointer back?
for (i = 3; < argc; i++) { printf("%s\n", argv[i]); pattern(determinefile(argv[i]), argv[2]); } file* determinefile(char* file) { if (strcmp(file,"getty.txt")) return getty; else if (strcmp(file, "shakes.txt")) return shakes; else if (strcmp(file, "genesis.txt")) return genesis; else return null; }
input:
grep getty.txt genesis.txt shakes.txt
output:
getty.txt
shakes.txt: word's stage,
shakes.txt: , men , women merely players.
shakes.txt: have exits , entrances;
genesis.txt
getty.txt: 4 score , 7 years ago our fathers brought forth, upon this
getty.txt: continent, new nation, conceived in liberty, , dedicated the
shakes.txt
c strcmp returns 0 if strings match. try:
if(strcmp(a, b) == 0) {/* ... */}
Comments
Post a Comment