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 to write syntax that can validate allow only one space input from user? Example, if the user input
"eat_food" it is VALID , when user enter "eat__food"(with 2 spaces) it would be INVALID..
and then show the appropriate error message to return right input?
This can be checked with strstr():
#define IS_VALID_INPUT(input) !strstr(input, " ")
This will result in 1 if there is not more than one space in the input, and 0 otherwise.
After the following code, n is the number of spaces in the string str.
Then you can check it.
int i, n = 0;
for (i = 0; str[i]!='\0'; i++)
n = (str[i] == ' ') ? (n+1) : n;
Related
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 1 year ago.
Improve this question
basically, I want to create a Position/location ruler which shows each numeric position starting at 1. let's say, if the characters in the above statement are 20 then in the next line 12345678901234567890 should be printed. similarly, if the characters are 30 then 123456789012345678901234567890 should be printed.
how can I do that?
Let's say n is the length you need to match
int n = 20; // or 30, or whatever
for (int i = 0; i < n; i++) printf("%d", (i + 1) % 10);
puts(""); // add newline
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 2 years ago.
Improve this question
I am having trouble with the following line of code.
//check number of words
if ((isblank(s[i]) != 0 && isblank(s[i+1] == 0)))
words++;
I would like to count the number of "blanks" that is followed by a non-blank, but combining these 2 isblanks do not seem to count correctly. Could someone please help me out?
I think it is a typo problem, your bracket is not in the correct place.
In this case the isblank() function get TRUE parameter if the s[i+1] is equal to 0, otherwise FALSE:
isblank(s[i+1] == 0)
I believe you wanted the to write the following:
isblank(s[i+1]) == 0
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 years ago.
Improve this question
I want to be able to do something like pause the program after displaying 10 characters of ASCII values and say Continue or something to resume.
I use Visual Studio 2017 if that of any use.
char str[] = "This is my string of text that will be outputted. After every"
" ten characters, this will be interrupted.\n";
size_t i;
for (i = 0; str[i] != '\0'; ++i) {
putchar(str[i]);
if (i % 10 == 0) {
printf("Press any key to continue . . .\n");
getchar();
}
}
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 7 years ago.
Improve this question
I'm really new to programming so please help me.
Here's my algorithm:
Enter a number
If the number is greater than 26
Subtract 26 from the number
Until the number is less than 26
Then display the final result
How do I write the code for this?
Thank You!
Try this. But next time do put some effort when formulating your question
if (scanf("%d", &n) == 1) {
while (n >= 26) {
n -= 26;
}
printf("%d", n) ;
}
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 7 years ago.
Improve this question
I know we use ctype.h for various comparisons.I can make a program where i have to check weather the given character is an UPPER CASE or LOWER CASE.
But suppose i have entered a string "Singh21$"
then how to check that this string contains an uppercase,a dollar sign and at least a number.
If a string contains these three then say "its a strong password".
You can try like this:
for(int i =0; i < strlen(stringPassword); ++i)
{
if( islower(stringPassword[i]) )
hasLower = true;
if( isupper(stringPassword[i]) )
hasUpper = true;
if( isdigit(stringPassword[i]) )
hasDigit = true;
if( isalnum(stringPassword[i]) )
hasSpecial = true;
}
And if all the flags are true then consider it as strong password.