Home>
Problem i am experiencing
To search for a specific character string in the character string entered from the keyboard
I wrote the following code, but
The result is not output.
How should I fix it?
N represents the number of characters to be entered.
S is a specific character string T is the character string to be entered.
The strings must be in order.
It is valid if the input string contains only one character.
Example) Check string "take"
The entered string "mistake" valid
"mistook" invalid
"mitaike" valid
# include<stdio.h>
int main (void) {
int N, i, j, k;
char S [11];
char T [21];
scanf ("% d",&N);
scanf ("% s", S);
for (i = 0;i<N;i ++) {
scanf ("% s", T);
j = 0;
k = 0;
while (S [j]! = '\ 0') {
while (T [k]! = '\ 0') {
if (T [k] == S [j]) {
while (T [k]! = S [j]) {
k ++;
j ++;
if (T [k]! = S [j]) {
k ++;
if (T [k]! = S [j]) {
k--;
k--;
j--;
break;
}
}
if (S [j + 1] == '\ 0') {
printf ("valid \ n");
break;
}
}
}
k ++;
}
j ++;
}
printf ("invalid \ n");
}
return 0;
}
-
Answer # 1
-
Answer # 2
I tried using strstr and strncmp.
# include
// scanf, puts #include // strlen, strstr, strncmp int main (void) { int N, i, j, valid, len; char S [110], T [210], U [110], * p; if (scanf ("% d",&N)! = 1) return 1; scanf ("% 109s", S); for (i = 0;i
Related articles
- 3b the character string read from the file cannot be output in reverse order
- how to output a newline separated character string in c language
- php i want to judge whether a character string with a specific pattern exists and store it in a variable if it exists
- please tell me how to output the character string
- c - different results are output in the program that gets the address of the variable
- file output in multithread in c language
- google apps script - gas i want to output the edit time of a specific cell to another specific cell
- how to send output of child process to pipe and monitor pipe in parent process
- the character count using isupper is different
- what is a non-hexadecimal character in the isxdigit();function? '\n' is not a hexadecimal character, but i would like to know wh
- c - output day of week time
- i want to clean up the output method for multiple arrays in c language
- comparison of character strings in c language
- no output when executed
- python - what is the character code of the program standard output?
- characters in the printf function are not output
- i want to turn on and off the arduino led by serial communication (character string)
- display of character string input
- python 3x - a program that determines whether or not the same character string can be created by joining any of the four input c
- awk comment out a specific character string and add the character string
Trends
Created and tested with Compile and Execute C Online (GNU GCC v7.1.1).
The input section is broken.