Create a username with C language [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 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

Related

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 to read multiple lines in string until specified character in C [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
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.

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.

Sending arbitrary bytes to fgets from stdin [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 6 years ago.
Improve this question
I'm prompting for a user supplied string using fgets(user_input, input_len, stdin). How can I send, for instance, the byte represented by hex \x04 to the program?
You can do
$ echo -n -e '\x04' | your-program
NOTE: On POSIX echo only octal values are allowed.
If you can get the bytes you want into a file, you can run
your-program < file

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