C Programming/String Manipulation: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 1: Line 1:
== Equality Check ==
== Equality Check ==
=== Case Sensitives ===
<syntaxhighlight lang="c">
//main.c
#include <stdio.h>
#include <conio.h>
#include <string.h>
int main()
{
    char name[60];
    char halt[60] = "exit";
    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;
}
</syntaxhighlight>
=== Ignore Case ===
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
//main.c
//main.c
Line 14: Line 39:
         scanf("%s", name);
         scanf("%s", name);


        //if(strcmp(name, halt) == 0){
         if(stricmp(name, halt) == 0){
         if(stricmp(name, halt) == 0){
             return 0;
             return 0;

Revision as of 01:59, 5 February 2018

Equality Check

Case Sensitives

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

int main()
{
    char name[60];
    char halt[60] = "exit";
    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;
}

Ignore Case

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

int main()
{
    char name[60];
    char halt[60] = "exit";
    for(int i=0;i<10;i++){
        printf("Enter your name: ");
        scanf("%s", name);

        if(stricmp(name, halt) == 0){
            return 0;
        }
        printf("Hello %s!\n", name);
    }
    return 0;
}