9868 35 Light Poster

1. Use code tags.
2.

scanf("&c", &code);

3. Your do while will print invalid code even if someone inputs a valid code.
4. Use switch statements instead of if-else.
5. For double I think the format specifier is %f only and not %lf, but not sure.
6. Indent your code properly.

9868 35 Light Poster

Could u gv me the website tat can download c programing the notes n the example? Thx^^

Google C programming tutorials and you will find more than a ton.

9868 35 Light Poster

Something like

do {

/* your code here */
} while (condition)

You forgot the semicolon after the while.:icon_smile:

9868 35 Light Poster

Believe me nobody is gonna help you unless you show some progress in your assignment.

9868 35 Light Poster

goto makes the code unreadable and hard to debug. The only place where goto is advisable is coming out of a nested loop.

9868 35 Light Poster

Hello, simple program here i can't seem to get to work. In a nutshell the program reads characters into an array using getchar and then prints them in a loop, although the numbers printed are not the ones i entered! thanks in advance

#include <stdio.h>

#define MAXSIZE 100 /*max array length*/

int arrlen(int []);

int main()
{
	int c, i = 0;
	int s[MAXSIZE];
	
	while((c=getchar()) != EOF && c != '\n'){ /*while the chars read havn't reached a new line or EOF */
		s[i++] = c; /*Read them into an array*/
		if(c == '\n'){
			s[i++] = c;
			}
		}
	s[i] = '\0'; /* terminate the array */
	
	for(i=0;i<arrlen(s);++i){
		printf("%d\n", s[i]);
		}
	return 0;
}

int arrlen(int array[])
{
	int i;
	
	for(i=0;array[i] != '\0';++i) 
	;
	return i; /*return legnth of the array*/
}

There is a library function strlen() in string.h which returns the length of the string. The only thing you need to do is just change the %d to %c in printf coz you are entering the characters and want teh output of those characters not their ASCII values.

9868 35 Light Poster

Thanks
I thought it was some kind of error deal.
What do you mean exactly, "It's on main()"

Adding to jephthah's reply, return 0 is optional in C99 standards. So you can remove it.

9868 35 Light Poster

No. According to C standards main should only return 0, nothing else. Keep in mind it's a special function, you can't do things you do with other ones.

9868 35 Light Poster

Hello...

Im a newb to both C programming and DaniWeb ..

the prob is tht i try to compile this program in TurboC3

#include <stdio.h>
#include<Conio.h>

main()
{
printf( "hello" );
getch();
}

when i press " alt+F9 " it says " Warning:: program should return a value" and no errors

When i press " Alt + F5 " I see nothing but a black screen and cursor on it (like in logo) when i have to get Hello....

wht can be the problem...

anything wrong in the program?

plz help me...

regards
yesh

1.CTRL+F9: to see the output
2. main should return int and nothing else
3. C is case sensitive, so Conio.h is wrong.
4. If I'm not wrong, ALT+F5 is used to hold the screen if you're not using getch().
5. Use code-tags to post your code.

9868 35 Light Poster

Your code is full of errors.
1. Check for matching curly braces.
2. main is returning "sum", it should return 0
3. Check for semicolons
4. C is case sensitive. What are ROWSIZE, COLSIZE?