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

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.

Related

Why the array is giving me random values while printing the elements of array which does not exits? [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 5 months ago.
Improve this question
here's the image of that program
While I tried to print the values of array suppose of length x,
its prints correctly but when I tried to print the array with different length rather than predefined length then its giving random values ...
how .. ?
Accessing an array out of bounds* will give undefined behavior. It will compile and run, but the results are not predictable.
Arrays in C are indexed starting at 0. An array of nine elements has a maximum index of 8. You have accessed elements 9 and 10.

Reverse the order of the words in C [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 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.)

Create a username with C language [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 have a to create a program where the user should create a username with minimum of 8 characters and maximum of 12 characters. What should I use for this one? I was thinking to use an array but I am not really sure of how I will set it with minimum of 8 characters, so maybe an array will not work. Is there any other option that I could use???
You can use do-while to check the input.
So it will loop everytime the input is wrong
do{
printf("Username : ");
//scanf here
}while( strlen(your variable) < 8 || strlen(your variable) > 12 );
Everytime the user input username with less than 8 character or more than 12 character, it will ask to input again

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.

Converting an int to string without using library functions in C? [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 8 years ago.
Improve this question
How do you convert an int to a string without using library functions in C?
You can achieve this by extracting each bits one by one, like this
str[i] = (char)( (num % 10) - 48 )
48 has to be subtracted because an integer value changing to character goes through an ASCII conversion. Keeping the above line in a loop, that would run for each digit in the number, should do the trick..

Resources