Quote
Enter a compound: H2SO4
H2
S
O4
Enter a compound: Bye
GoodBye!
H2
S
O4
Enter a compound: Bye
GoodBye!
I have done the code, but it gives me errors and am unsure about it, would you be able to assist?
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
char s[81] = *s[i];
int len = strlen(s), i;
for (i = 0; i < len; i++)
s[i] = toupper(s[i]);
puts(s);
while (s[i] != 0)
{
printf("\nEnter a compound:");
scanf("%c", &s[i]);
if(s[i] == "Bye")
{
printf("Goodbye!\n");
break;
}
for( i = 0; i < len; i++)
if(isdigit(s[i]))
printf("%c", s[i]);
printf("\n");
system("pause");
return (0);
}
Error from the terminal
Quote
*****@ubuntu:~/week10$ gcc -o compound compound.c
compound.c: In function ‘main’:
compound.c:9: error: ‘i’ undeclared (first use in this function)
compound.c:9: error: (Each undeclared identifier is reported only once
compound.c:9: error: for each function it appears in.)
compound.c:18: warning: incompatible implicit declaration of built-in function ‘printf’
compound.c:19: warning: incompatible implicit declaration of built-in function ‘scanf’
compound.c:21: warning: comparison between pointer and integer
compound.c:34: error: expected declaration or statement at end of input
*****@ubuntu:~/week10$
compound.c: In function ‘main’:
compound.c:9: error: ‘i’ undeclared (first use in this function)
compound.c:9: error: (Each undeclared identifier is reported only once
compound.c:9: error: for each function it appears in.)
compound.c:18: warning: incompatible implicit declaration of built-in function ‘printf’
compound.c:19: warning: incompatible implicit declaration of built-in function ‘scanf’
compound.c:21: warning: comparison between pointer and integer
compound.c:34: error: expected declaration or statement at end of input
*****@ubuntu:~/week10$
*** please note, name has been removed for privacy reasons.


Sign In
Create Account


Back to top









