C Programming/String Manipulation: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
(Created page with "== Equality Check == <syntaxhighlight lang="c"> //main.c #include <stdio.h> #include <conio.h> #include <string.h> #include <stdlib.h> int main(void) { char halt[60] = "e...")
 
Line 12: Line 12:
     char name[60];
     char name[60];
     for(int i=0;i<10;i++){
     for(int i=0;i<10;i++){
         printf("Enter your name:");
         printf("Enter your name: ");
         scanf("%s", name);
         scanf("%s", name);
        printf("Hello %s!\n", name);
         if(strcmp(name, halt) == 0){
         if(strcmp(name, halt) == 0){
             return 0;
             return 0;
         }
         }
        printf("Hello %s!\n", name);
     }
     }
     return 0;
     return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 23:15, 4 February 2018

Equality Check

//main.c
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
    char halt[60] = "exit";
    char name[60];
    for(int i=0;i<10;i++){
        printf("Enter your name: ");
        scanf("%s", name);
        if(strcmp(name, halt) == 0){
            return 0;
        }
        printf("Hello %s!\n", name);
    }
    return 0;
}