Reverse the order of the words in C [closed] - c

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.)

Related

C char arrays for user input [closed]

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 2 years ago.
Improve this question
I rarely log on and am very new to the C language, therefore I apologize if this is a duplicate question or if this is a silly query.
I'm currently learning C and am hitting a wall with strings. I understand that char arrays are used in place of strings in the language. My question is, is there a better way than to assign an arbitrary value when declaring a char[] for user input(i.e setting the size of the array to one value when the user might enter more or less than that amount of characters)?
If you're on a POSIX system (basically anything that's not Windows), you can use getline(3) to do this. It will automatically allocate a buffer of the right size for you. Otherwise, you'll have to guess a length, allocate that, then read the input up to that length, and if you guessed wrong, use realloc to increase your guess and try again.

working of these two lines of code in the program [closed]

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 4 years ago.
Improve this question
total+=!used[str[i]-'a'];
used[str[i]-'a']=1;
It is the condition for checking the characters and saving the value in the variable total.
The total variable will contain the number of unique characters in the array str.
This happens because you increment the count(total+=!used[str[i]-'a']) only if you haven't already marked the character as visited. If you incremented it, you mark it as such in the next line (used[str[i]-'a']=1) so that you wont count it again.
The notation str[i]-'a' is used to shift the ascii values of the characters from 0 to 25 (instead of 97 to 122) so that you can spare some space in the array.

How can i add blank space inside printf in c programming? [closed]

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 want to add two blank space inside c programming print statement. I have try but it always count one single space. How can i add another one ?? If i use \t then it count 4 space as set.
printf("Hello Dhaka!");
printf("Hello Dhaka!"); adds 2 spaces, since it contains 2 spaces.
The problem must be related to your output. Perhaps the console uses some strange font that is not fixed-width.

string equals or substring search [closed]

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.

What does "Print the string using twice the length as the width." mean? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I can't ask my lecturer at this moment seeing as where i am it's late at night and on the weekend.
this is the question:
"Write a program that inputs a string from the keyboard and determines the length of the string. Print the string using twice the length as the width."
The bolded bit is the part i don't understand.
He means to print with padding
e.g.
Hello <-- not padded
Hello <-- padded in 10-char field, right justified

Resources