Hi,
I am trying to get the input from the user as strings, the end of which is characterized by the string "end". So, the desired output will be the number of strings entered till the string "end". Say, the user inputs :
hello
world
1234
end
the output should be :
you entered 3 inputs
The code with which I was trying to achieve the above is :
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char *str[30][100]={'\0'};
int n=0,i=0,counti=0,flag=0;
char *fun_str_ip(char *str_ip[30][100],int num);
int main()
{
printf("Start Entering Inputs :");
while(!flag)
{
if(strcmp(*str,"end")==0)
{
flag=1;
break;
}
else
{
for(i=0;i<counti;i++)
{
fun_str_ip(*str_ip,i);
}
counti++;
}
}
printf("You have entered %d inputs\n",counti);
}
char *fun_str_ip(char *str_ip[30][100],int num)
{
printf("Enter Input Number %d :",num);
scanf("%s",&str_ip[30][num]);
}
but this was my second attempt.
The following was my first :
Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
*char inpc[30][100];
int i,counti=0,counta=0;
do
{
printf("Enter The Inputs (Enter END when done) :\n");
for(i=0;i<100;i++)
{
scanf("%s",&inpc[30][i]);
counta++;
if(inpc[30][i]=="END\0"||"end\0")
{
break;
}
counti++;
}
break;
}while(inpc[30][100]!="END\0")
printf("You have entered %d inputs\n",counti);
return(0);
}
The moment i finished typing both the snippets i had this feeling of deja vu. It so occured that both didn't run the way they were intended to. I know I'm missing something really important. Can someone please point out what is missing and help me? Thanks in advance.