473,401 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

converting strokes from c++ to c!

hi,

i have a problem to change this C++ code language to C language...



Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. void choosePlay(char);
  5. void playGame(int,int,int,int);
  6. void match(int[][4]);
  7. int r1,r2,c1,c2;
  8. char comma;
  9. int cards[4][4]={{1,3,2,4},{4,2,3,1},{5,7,6,8},{8,6,7,5}};
  10.  
  11. void main()
  12. {
  13.  
  14.     char click;
  15.     char newcard;
  16.  
  17.  
  18.  
  19.     cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n";
  20.     cout<<"@                                                                            @\n";
  21.     cout<<"@                    ##  ## #### ##  ## #### #### # #                      @\n";
  22.     cout<<"@                    # # # # #    # # # # #  # #  # # #                      @\n";
  23.     cout<<"@                    #  #  # ###  #  #  # #  # #### ###                      @\n";
  24.     cout<<"@                    #    # #    #    # #  # # #    #                      @\n";
  25.     cout<<"@                    #    # #### #    # #### #  # ###                      @\n";
  26.     cout<<"@                                                                            @\n";
  27.     cout<<"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n";
  28.  
  29.  
  30.     choosePlay(click);
  31.  
  32.   do{
  33.       playGame(r1,c1,r2,c2);
  34.         match(cards);
  35.  
  36.       cout<<"any card does not open?((Y)es or (N)o)";
  37.       cin>>newcard;
  38.  
  39.   }while(newcard =='Y');
  40.  
  41.     //this pushes the next board onto a blank screen
  42.     for (int b=0; b<=5; b++){
  43.         cout<<endl;
  44.     }
  45.  
  46.     cout<<"YOU ARE THE WINNER!!"<<endl;
  47.   getch();
  48. }
  49.  
  50. //----------------------------------------------------------------------------//
  51.  
  52. void choosePlay(char c){
  53.  
  54.  
  55.     cout<<"WELCOME TO MEMORY GAME"<<endl;
  56.     cout<<"DO YOU WANT TO PLAY THIS GAME?\n"<<endl;
  57.     cout<<"(y/n)\n\n";
  58.     cin>>c;
  59.  
  60.     if(c=='y'){
  61.         //display board
  62.         cout<<"\n\n    1  2  3  4\n"<<endl;
  63.         cout<<"  ";
  64.  
  65.         for (int i=0; i<=6; i++)
  66.         {
  67.             cout<<" -";
  68.         }
  69.       cout<<endl;
  70.  
  71.     for (int r=0; r<4; r++)
  72.     {
  73.         cout<<r+1<<" | ";
  74.         for (int c=0; c<4; c++)
  75.         {
  76.             cout<<" * ";
  77.         }
  78.         cout<<endl;
  79.     }
  80.     cout<<endl;
  81.   }
  82.     else if(c=='n') {
  83.             cout<<"Thank you for enter this game"<<endl;
  84.       }
  85. }
  86.  
  87.  
  88. //-----------------------------------------------------------------------------//
  89.  
  90. void playGame(int s1,int d1,int s2,int d2){
  91.  
  92.  
  93.     //selection
  94.     cout<<"Please insert the first card row and column seperated by a comma.\n";
  95.     cin>>s1>>comma>>d1;
  96.     cout<<"Please insert the second card row and column seperated by a comma.\n";
  97.     cin>>s2>>comma>>d2;
  98.     //fix
  99.     s1--;
  100.     d1--;
  101.     s2--;
  102.     d2--;
  103.     cout<<s2<<d2;
  104.  
  105.     //reveal
  106.     cout<<"\n\n    1  2  3  4\n";
  107.     cout<<"  ";
  108.     for (int i=0; i<=6; i++)
  109.     {
  110.         cout<<" -";
  111.     }
  112.     cout<<endl;
  113.  
  114.     for (int r=0; r<4; r++)
  115.     {
  116.         cout<<r+1<<" | ";
  117.         for (int c=0; c<4; c++)
  118.         {
  119.             if ((r==s1)&&(c==d1))
  120.             {
  121.               cout<<"  ";
  122.             }
  123.             else if((r==s2)&&(c==d2))
  124.             {
  125.                 cout<<"  ";
  126.  
  127.             }
  128.             else
  129.             {
  130.                 cout<<" * ";
  131.             }
  132.         }
  133.         cout<<endl;
  134.     }
  135. }
  136.  
  137. //----------------------------------------------------------------------------//
  138.  
  139. void match(int cards[4][4]){
  140.  
  141.     //match?
  142.  
  143.     if (cards[r1][c1]==cards[r2][c2])
  144.     {
  145.     cout<<"  ";
  146.     }
  147.   else
  148.     {
  149.     }
  150. }
i hope someone can help me to change it...
thanks for your cooperation :)
Nov 12 '10 #1
2 1490
newb16
687 512MB
just replace all console i/o operators with corresponding printf and scanf.
Nov 13 '10 #2
Hey I rewrote and fix all the problems:
there is still some problem with the logic in if conditions. If you have any question write me back i will gladly assist you =).

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3.  
  4. void choosePlay(char);
  5. void playGame(int,int,int,int);
  6. void match(int[][4]);
  7. int r1,r2,c1,c2;
  8. char comma;
  9.  
  10.  
  11.  
  12. int cards[4][4]={{1,3,2,4},{4,2,3,1},{5,7,6,8},{8,6,7,5}};
  13.  int main()
  14. {
  15.  
  16.     char click;
  17.     char newcard;
  18.  
  19.  
  20.  
  21.  
  22.     printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
  23.     printf("@                                                                            @\n");
  24.     printf("@                    ##  ## #### ##  ## #### #### # #                      @\n");
  25.     printf("@                    # # # # #    # # # # #  # #  # # #                      @\n");
  26.     printf("@                    #  #  # ###  #  #  # #  # #### ###                      @\n");
  27.     printf("@                    #    # #    #    # #  # # #    #                      @\n");
  28.     printf("@                    #    # #### #    # #### #  # ###                      @\n");
  29.     printf("@                                                                            @\n");
  30.     printf("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n");
  31.  
  32.  
  33.     choosePlay(click);
  34.  
  35.   do{
  36.       playGame(r1,c1,r2,c2);
  37.         match(cards);
  38.  
  39.       printf("any card does not open?((Y)es or (N)o)");
  40.       scanf("%c",&newcard);
  41.  
  42.   }while(newcard =='Y');
  43.  
  44.     //this pushes the next board onto a blank screen
  45.     int b=0; //cannot be in for loop cannot be created 
  46.     for (b=0; b<=5; b++){
  47.         printf("\n"); //replace endl with \n for newline
  48.     }
  49.  
  50.     printf("YOU ARE THE WINNER!!\n");
  51.   getch();
  52. }
  53.  
  54. //----------------------------------------------------------------------------//
  55.  
  56. void choosePlay(char c){
  57.  
  58.  
  59.     printf("WELCOME TO MEMORY GAME\n");
  60.     printf("DO YOU WANT TO PLAY THIS GAME?\n\n"); //place 2 newline dint know if that is what you wanted
  61.     printf("(y/n)\n\n");
  62.     scanf("%c",&c);
  63.  
  64.     if(c=='y'){
  65.         //display board
  66.         printf("\n\n    1  2  3  4\n\n");
  67.         printf("  ");
  68.          int i=0;
  69.         for (i=0; i<=6; i++)
  70.         {
  71.             printf(" -");
  72.         }
  73.       printf("\n");
  74.  int r=0;
  75.     for (r=0; r<4; r++)
  76.     {
  77.         printf("%d \"| '",r+1);
  78.         int c=0;
  79.         for (c=0; c<4; c++)
  80.         {
  81.             printf(" * ");
  82.         }
  83.         printf("\n");
  84.     }
  85.     printf("\n");
  86.   }
  87.     else if(c=='n') {
  88.             printf("Thank you for entering this game ");
  89.  
  90.       }
  91. }
  92.  
  93.  
  94. //-----------------------------------------------------------------------------//
  95.  
  96. void playGame(int s1,int d1,int s2,int d2){
  97.  
  98.  
  99.     //selection
  100.     printf("Please insert the first card row and column seperated by a comma.\n");
  101.     scanf("%d",&s1);
  102.     scanf("%d",&d1);
  103.  
  104.     printf("Please insert the second card row and column seperated by a comma.\n");
  105.  
  106.     scanf("%d",&s2);
  107.     scanf("%d",&d2);
  108.  
  109.     //fix
  110.     s1--;
  111.     d1--;
  112.     s2--;
  113.     d2--;
  114.     printf("%d %d",s2,d2);
  115.  
  116.     //reveal
  117.     printf("\n\n    1  2  3  4\n");
  118.     printf("  ");
  119.     int i=0;
  120.     for (i=0; i<=6; i++)
  121.     {
  122.         printf(" -");
  123.     }
  124.     printf("\n");
  125.  int r=0;
  126.     for (r=0; r<4; r++)
  127.     {
  128.         printf("%d | ",r+1);
  129.         int c=0;
  130.         for (c=0; c<4; c++)
  131.         {
  132.             if ((r==s1)&&(c==d1))
  133.             {
  134.               printf("  ");
  135.             }
  136.             else if((r==s2)&&(c==d2))
  137.             {
  138.                 printf("  ");
  139.  
  140.             }
  141.             else
  142.             {
  143.                 printf(" * ");
  144.             }
  145.         }
  146.         printf("\n");
  147.     }
  148. }
  149.  
  150. //----------------------------------------------------------------------------//
  151.  
  152. void match(int cards[4][4]){
  153.  
  154.     //match?
  155.  
  156.     if (cards[r1][c1]==cards[r2][c2])
  157.     {
  158.     printf("  ");
  159.     }
  160.   else
  161.     {
  162.     }
  163.  
  164.     //label if you want to start again
  165.     //cls will clear screen  and pause 
  166.     //system("pause");
  167.     //system("cls");
  168.     //main(); call again if you want to start or write do-while to start the entire process
  169.  
  170.  
  171. }
  172.  
Nov 17 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
6
by: Al Bahr | last post by:
H I need to combine Ink strokes with the background image into a bit map. Would appreciate any help Thank A
3
by: Paulers | last post by:
Hello, I need to emulate keyboard strokes from a console application. The console application monitors a textfile and when something is matched in a text file I need the matched string outputted...
1
by: sreenulanka | last post by:
I have five panel each one layout is set to gridbag layout.and also i have one main panel, layout is box layout.all components add to container.my page is larger than screen.it is not moving with...
11
cheezylu
by: cheezylu | last post by:
I'm working on a site where my client will be able to maintain some of the text on the site using input boxes and such driven by PHP and MySQL. The problem I am running into is making it easy for...
0
by: abcd | last post by:
Is there a way to capture key strokes on a system using python (other than pyHook)? can wxPython capture keystrokes for the system (not just, say a text box)? thanks
4
by: =?Utf-8?B?QWxleGFuZGVy?= | last post by:
Hi! I am new to C#. I read two C# books in the last two days which only covered the basics. And now I am on my third day. The books were really bad, because they did not cover windows applications,...
11
by: shadyabhi | last post by:
How can i accept key strokes like Ctrl+A etc etc ... i mean combination of 2 keys... Pls give a small peice of code to demonstrate... i use gcc under linux platform
3
by: kiksu | last post by:
Hi, I have problem,that I have to change programming language from C++ to C, but i don't get how to make these strokes work in C language! There is the following strokes, what I need to change: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.