I have written this code where i want to input a text, say "helloWorld"
and then compare it such that if it matches the entered text then it should print the text 101 times. But, it is not working as it does not seem to compare the string in the if (string == "helloWorld")
and it directly skips to the else
part. Please provide necessary details on how to do it.
Here is my code:
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char string[30];
clrscr();
printf("Enter the string 'helloWorld' if you wanna see magic\n");
scanf ("%s", string);
printf("Your enterred Input is %s\n", string);
if (string == "helloWorld")
{
for (i=0;i<=100;i++)
{
printf("%s\n",string);
}
}
else
{
printf("Invalid Input\n");
}
getch();
}
Also, I know that in C if we enter a string using char variable[sting_length]
in C, we have to enter the string without any spaces. But, is there any way to enter the string like "Hello World" and still have the whole thing printed/compared altogether?