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 9 years ago.
Improve this question
I want to compare if two arrays are equal. I know i have to loop through both arrays and see if they match. But how do i determine the longest array to use as an end to the loop.
EDIT
if (intToRoman(roman_integer, result))
{
for(int i = 0; i < ???; i++ )
}
for example,
roman_integer[] = "MMM"
result[] = "MMMDCCLXXX"
use strlen function to find the length of greatest string, like
int greatestlength=arrlength(a);
if(greatestlength<arrlength(b))
{
greatestlength=arrlength(b);
}
use strlen inside of arrlength or directly or write your own code in arrlength whatever you want
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 8 months ago.
Improve this question
#include<studio.h>
int main()
{
int a=5,i;
i!=a>10;
printf("i=%d",i);
return 0;
}
This code should print i=1 but it is printing i=0 Why is it so?
That's because you don't do anything to i.
Your "i!=a>10" evaluates to false, but the result is not stored into a variable.
As it is mentioned in the comments, you need something like this:
int a = 5;
int i = !(a > 10);
The != is mostly used in if-clauses, like
if (a != 0) {...}
I hope this helps. ;)
It's not printing because:
the variable i is not initialized
the second statement should be changed and be a variable int i = !(a > 10)
Returning a value and printing it are different things, but that's not the point of the question.
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
Here is the code for copying string in C.
#include <stdio.h>
int main()
{
char s1[100], s2[100];
int i;
printf("Enter string s1:");
fgets(s1,sizeof(s1),stdin);
for(i=1;s1[i]!='\0';i++)
{
s2[i]=s1[i];
}
s2[i]='\0';
printf("%s",s2);
}
However, when I enter "How are you?", the copied string become "#ow are you?"
Since arrays start at 0, your for loop should look like this
for(i=0;s1[i]!='\0';i++) {
// ^ 0, not 1
The for-loop must start at the index 0. So change your for loop to this:
for(i=0;s1[i]!='\0';i++)
{
s2[i]=s1[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 7 years ago.
Improve this question
//I wanted to separate last digit i.e."2" as an int from "hello.mp4;2" Here is the code:
int main()
{
char str[30];
int separate = 0;
strcpy( str, "hello.mp4;2" );
sscanf(str, "%*[^;]%d", &separate);
printf("%d\n",separate);
return 0;
}
and it is not woriking...
Change the sscanf to:
sscanf(str, "%*[^;];%d", &separate);
I.e., you need to match the semicolon ; after the string that excludes it. The portion in the square brackets matches the string that precedes the semicolon, leaving ;2. So you then need to match the semicolon ; before trying to match the 2.
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
How many times the while loop is executed in the below prog if short int is of 2 bytes?
main()
{
int j = 1;
while(j <= 255);
{
printf("%d",j);
j++;
}
return 0;
}
i think it should be 255 times but its not correct. Can anyone tell me why?
You have a semicolon at the end of your while-line. The while loop, consisting of the statement ;, executes "infinitely" many times.
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'm trying to create a while loop in C, it says that build is successful, however it doesn't print out anything. I don't really see whats wrong, it doesn't show anything in the console.
int main()
{
int w = 0;
while (w >=100){
printf("w = %i" , w);
w++;
}
return 0;
}
You define w=0 and in the next line you write "while w is greater or equal than 100", which cannot work.
Try
while (w <= 100)