Pause program after displaying ten characters [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 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();
}
}

Related

Issues dynamically allocating strings with 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 10 days ago.
The community is reviewing whether to reopen this question as of 10 days ago.
Improve this question
I know strings end with '/0' in C. While I'm dynamically allocating memory for a string, how do I handle that?
Also, how would you print out a dynamically allocated string? Because I've tried the regular way to print out a string and it did not work.
For the first question, I tried:
int len;
scanf("%d", &len);
char* str = (char*)malloc(sizeof(char)*len);
for (int i = 0; i<len; ++i){
scanf("%c", (str+i));
}
For the second question, I tried
printf("%s", *str);

In C language, how can I print 1234567890 to create a position/location ruler? [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 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

How to copy all chars(include '\0') from one array to another without using strcpy function? [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 3 years ago.
Improve this question
copy all characters from one character array to another without using strcpy function.
char s1[80],s2[80];
int i;
printf("input s2");
scanf("%s",&s2);
for(i=0;i<=strlen(s2);i++)
s1[i]=s2[i];
printf("s1:%s",s1);
Instead of scanf, using gets function for getting input with spaces.
#include<stdio.h>
int main()
{
char s1[80],s2[80];
int i;
printf("input s2");
// scanf("%c",&s2);
gets(s2);
printf("%d",strlen(s2));
for(i=0;i<strlen(s2);i++)
{
s1[i]=s2[i];
}
printf("s1:%s",s1);
}

Is it possible to make a string such as "G" equal a specific number like 50? [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
For example if I had the letter "B" in a array and want to count how many there are,could I make "B"=1 so I can easily count the number of b's.I do not think this is typecasting since I am do not want to make "B" itself = int B
You don't need to assign to a string, just use an ordinary variable.
int b_count = 0;
char *string = "This is a B and this is another B";
for (char *p = string; *p != 0; p++) {
if (*p == 'B') {
b_count++;
}
}
printf("There are %d B's in the string\n", b_count);

Validation of space in C syntax [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 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;

Resources