c - The program does not print the data correctly -
hello have program accepts parameters , prints things according, problem program prints parameters instead of need printed. happy if tell me mistake , how fix thanks.
code -
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char** argv) { int i; for(i = 0; < argc ; i++) { if("/n") { printf("my name pop\n"); break; } } for(i = 0; < argc ; i++) { if("/b") { printf("my birthday 7.1.1999\n"); break; } } for(i = 0; < argc ; i++) { if("/f") { printf("my favorite food pizza\n"); break; } } for(i = 0; < argc ; i++) { if("/?") { printf("/n = print name\n/b = print birthday\n/f = favorite food\n"); break; } } }
horrible mis-use of c syntax. "it's bad, it's not wrong."
if("/n")
a constant string used way, checks if 'result' evaluates 0. tests address of constant string, , hey! it's not 0! code inside braces gets executed.
look in favourite reference how compare strings.
also, might want skip arg[0]
, because (usually) name of program.
Comments
Post a Comment