Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the code in question... printf(\"\ Please begin entering themailings...\

ID: 3613264 • Letter: H

Question

Here is the code in question...

    printf(" Please begin entering themailings... ");
    while (i<100){
    printf("Name:       ");
    fgets(line, sizeof(line), stdin);
        sscanf(line, "%s",&list[2].name);
        if (list[2].name == "end")printf("Raaaaaaar");

I actually want it to break a while statement but I used Raaaaaaarjust to see if the if statement was working. It is not. So i've gota structure set up and that's all working because i tried puttingin a test printf(list[2].name); after the sscanf part to make sureit was being fed in correct and it is, it'll print back whateveryou type in. So why when I type in end does it not printRaaaaaaar?? I just don't get it.

Thanks very much,

Tom Sturges.


p.s. I found a way around it, I used the codeif(strcmp(list[2].name), "end") == 0) printf("Raaar"),
       however that still don'tunderstand why the above code doesn't work :S

Explanation / Answer

please rate - thanks the reason is a string has a null character at the end of it toindicate the end. therefore you are comparing list[2].namewhich is probably a character array to a string "end" andsince "end" has a null at the end you are basically comparingapples and oranges which you can't do