Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there any function in C, that will find string exactly same as string , if there is no exact form, return first string that contains substring?
or i have to use first binary search for exact form, and then linear for substing
Under string.h,
strcmp(str1,str2); - returns 0 if strings are same, returns the difference between the strings if they are not same.
strstr(str1,str2); - finds whether str2 is a substring of str1.
You may want to use these two library functions and write the required logic.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to reverse the order of the words (not the characters) in a specific string with constant extra space in linear time?
First, reverse the whole string (by swapping the first and the last character, towards the middle, etc). This should be enough of a hint to get you started. If not, read on:
Then reverse the order of the characters in each word. Now the characters in each word are in the original order (they were reversed twice overall), but the words are in reverse order (the first word is now at the end, etc.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
So I have these two variables, a and c, they both have a space after them so when I'm trying to join them it prints "a c " and not "ac". How should I go on about removing the spaces?
set "a=%a: =%"
is one way. set the variable=%variablename:stringtoreplace=replacementstring%
The quotes ensure that any trailing spaces in the set line are not included into the value assigned.
The replacement string may be empty.
This is a general solution, replacing all strings matching stringtoreplace with the defined replacement.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Need to read everything until say *** comes up:
Input:
Hey there
how are
you
***
Output:
Hey there
how are
you
Would have used scanf("%[^***]s) but can't read all lines at once.
Only having basic C knowledge
The way I would do this is read one line at a time (with a funcion such as fgets instead of scanf) and then see if the line that you last read is equal to ***. You can use use strcmp to do that but you can also do it by hand if you are not allowed to use strcmp for some reason.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I just found a short code here, which would detect blank lines in a file. It used fgets() function in C library.
I wonder if character functions are better suited for files which have tabs, and perhaps continous spaces.
My qustion is what is the best way to parse a file for blank lines?
You can also use scanf(" %[^\n]s",string); in order to read spaces but fgets is best solution for your case.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is it possible in c programming language to check string with if else, and if it is, can someone please explain how, with some basic exampel. I would like to check if string matches a certain word. Thanks very much. For example if(n==0) instead of 0 to be a word.
To check for the contents of a string [whether is matches another], you cannot use == operator. You need to use strcmp() function with if condition.
check the man page here
If the strings match, it will return 0, otherwise, it will return non-zero. However, this is case-sensitive. ["Hello" and "hello" are not same]
Suppose, you want to check whether your string strcontains Hello or not. A pseudo-code will look like
if (! strcmp(str, "Hello"))
printf("String contains Hello\n");
else
printf("No Hello!!\n");