Thursday, July 30, 2009

How do i print a sentence in "C" Language?

hi all


i want to create a program in "C" that prints this sentence "My name is Sam" repetedly until i press ANY KEY:





do you have anyidea how ?





For Example


x=1;


while (x==1) printf("My Name is Sam\n");





i want exactly a program like this,,, but want it to stop printing Sam when i press any key





thats all


i guess its simple


but i still don't know how to do it lol

How do i print a sentence in "C" Language?
You need two processes parent and child , parent will wait for input , child will print , parent will kill child when it receives an input.
Reply:#include %26lt;stdio.h%26gt;


void main(){


while(!kbhit()){


printf("My Name is Sam\n");


}


printf("A key was pressed...");


}


---------------------------


use kbkit() to detect any key pressed on your keyboard ,when it detected one ,it returns 1,OR 0.





----------example----------------


My Name is Sam


My Name is Sam


My Name is Sam


My Name is Sam


My Name is Sam


My Name is Sam


My Name is Sam


My Name is Sam


A key was pressed...
Reply:#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;





void main()


{


int x=1;


while(x==1)


{


if(kbhit()) x=0;


else printf("my name is sam\n");


delay(500);


}





gtetch();


}











/* this program is the solution for ur question ,this works


even without delay statement but without that the computer executes the printing work so quickly that u may fail to notiece that it is printing*/


/*all the best*/


No comments:

Post a Comment