Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
Im receiving warnings like this "warning: array subscript has type 'char' [-Wchar-subscripts]" in lines 11, 12 and 15. Whats wrong with my code?
#include <stdio.h>
#include <ctype.h>
int main()
{
char s[1000], i, d, a;
printf("Enter a string: ");
fgets(s, 1000, stdin );
for(i = 0; s[i] != '\0'; i++){
if (isalpha(s[i])){
a++;
}
if (isdigit(s[i])){
d++;
}
}
printf("Number of digits: %d ... Number of letters: %d ", d, a);
return 0;
}
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am in C language
Arrays were implemented using input and output functions.
The code is as follows.
#include <stdio.h>
int main()
{
int n;
int arr[1000];
printf("Enter the number of numbers to enter : \n");
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
for(int i = n - 1; i >= 0; i--)
{
printf("&d ", arr[i]);
}
return 0;
}
However, after running the compilation, this resulted. Below is the (vscode, gcc) console window.
Enter the number of numbers to enter :
5
1 2 3 4 5
&d &d &d &d &d
I don't understand why the notation like %d %d %d appears here.
Adapted to the windows compiler, I feel pathetic. What is the problem
This line ie causing the issue:
printf("&d ", arr[i]);
You are printing not scanning for inputs, it should be like this:
printf("%d ", arr[i]);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int i,limit,sum=0;
int a[100];
setbuf(stdout,NULL);
printf("enter the limit");
scanf("%d",&limit);
printf("enter the values");
for(i=0;i<limit;i++)
{
scanf("%d",&a[limit]);
}
for(i=0;i<limit;i++)
{
sum=sum+a[i];
}
printf("the sum is : %d",sum);
return 0;
}
Output:
enter the limit3
enter the values3
3
3
the sum is : 19265880
The actual output should be 9
for(i=0;i<limit;i++)
{
scanf("%d",&a[limit]); //replace limit with i
}
You can see that scanf is reading into the array a[limit] instead of a[i]. This is causing the issue.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I'm reading data from standard input one character at a time and outputting the results to standard output. Every 10 characters, I want to have a new line. For example:
Input-
123456789101112
Output-
1234567891
01112
This is what I have so far, but it doesn't work.
if(numChars = 10) {
printf("\n");
numChars = 0;
}
#include <windows.h>
int main()
{
char test[] = "123456789101112123133431234567891011121231334312345678910111212313343";
int i = 0;
while (i < strlen(test))
{
printf("%c", test[i++]);
if (i % 10 == 0) {
printf("\n");
}
}
return 0;
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I type this code on Ubuntu 14.04
#include<stdio.h>
int main() {
int i, j, n;
scanf("%",&n);
for (i=0;i<=n;i++){
for (j=0;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}
but it print too much stars and it Continue until I close it.
Should be:
#include<stdio.h>
int main() {
int i, j, n;
scanf("%d",&n);
for (i=0;i<=n;i++){
for (j=0;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}
You forgot to tell scanf you were reading in an integer by using the %d argument
There is mistake in
scanf("%",&n);
it will be:
scanf("%d",&n);
to tell the complier that the value of n is an integer type.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I know that a string should be n+1 in length, but for some reason my program is printing the sizeof(string) as n-2.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char name [] = "Tom";
int x = sizeof(name);
int i;
printf("sizeof(name) = %d\n", i);
for(i = 0; i < x; i++)
{
printf("Character at %d is %c\n", i, name[i]);
}
return 0;
}
Can anyone explain why?
You're printing i, not x.
i was never initialized, so you get undefined behavior.