473,569 Members | 2,844 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to convert C++ code to C?

1 New Member
How can I convert the following code from C++ to C? any software?

Expand|Select|Wrap|Line Numbers
  1. #include<time.h>
  2. #include<fstream>
  3. #include<iostream>
  4. #include<stdlib.h>
  5. using namespace std;
  6. int sum;
  7. int q1(char q[60], char a1[20], char a2[20]);
  8. int q2(char q[60], char a1[20], char a2[20]);
  9. int q3(char q[60], char a1[20], char a2[20]);
  10. int q4(char q[60], char a1[20], char a2[20]);
  11. int q5(char q[60], char a1[20], char a2[20]);
  12. int q6(char q[60], char a1[20], char a2[20]);
  13. int q7(char q[60], char a1[20], char a2[20]);
  14. int q8(char q[60], char a1[20], char a2[20]);
  15. int q9(char q[60], char a1[20], char a2[20]);
  16. int q10(char q[60], char a1[20], char a2[20]);
  17.  
  18. int tem(char q[60], char a1[20], char a2[20]);
  19. int tem(char q[60], char a1[20], char a2[20]);
  20. void imran();
  21. int record();
  22. int main(){
  23.   char q[60];
  24.   char a1[20];
  25.   char a2[20];
  26.   printf ("\nChoose either the options 1, 2 or 3 depending on the answer next to it.\n\n";
  27.   sum = q1(q, a1, a2);
  28.   printf ( "\n");
  29.   sum = q2(q, a1, a2);
  30.   printf ( "\n");
  31.   sum = q3(q, a1, a2);
  32.   printf ( "\n"); 
  33.   sum = q4(q, a1, a2);
  34.   printf ( "\n");
  35.   sum = q5(q, a1, a2);
  36.   printf ( "\n");
  37.   sum = q6(q, a1, a2);
  38.   printf ( "\n");
  39.   sum = q7(q, a1, a2);
  40.   printf ( "\n"); 
  41.   sum = q8(q, a1, a2);
  42.   printf ( "\n");
  43.   sum = q9(q, a1, a2);
  44.   printf ( "\n");
  45.   sum = q10(q, a1, a2);
  46.   record();
  47. }
  48.  
  49.   ////////////////////////////////////////////////////////////////////
  50.   // These functions are the 2 templates for the questions each     //
  51.   // question calls either tem() or tem2()                          // 
  52.   ////////////////////////////////////////////////////////////////////
  53.  
  54.  
  55. int tem(char q[60], char a1[20], char a2[20])
  56. {
  57.   int res;
  58.   printf ( q ( "\n");
  59.   printf ("1) "( a1 ("\n");
  60.   printf ("2) "( a2 ("\n");
  61.   printf ("3) Exit program\n";
  62.   scanf  ( res);
  63.  
  64.   if (res==1){
  65.   sum=(sum+10);
  66.   }
  67.   else if (res==2){
  68.   } 
  69.   else if (res==3) {
  70.   printf ( sum (" out of 100\n";
  71.   record();
  72.   exit(1);
  73.   }    
  74.   else
  75.   {  printf ( "You must enter a number between 1 and 3.\n";
  76.   tem(q, a1, a2);
  77.   }
  78.   return sum;
  79.   }
  80.  
  81. int tem2(char q[60], char a1[20], char a2[20])
  82. {
  83.   int res;
  84.   printf ( q ( "\n";
  85.   printf ("1) "( a1 ("\n";
  86.   printf ("2) "( a2 ("\n";
  87.   printf ("3) Exit program\n";
  88.   scanf  ( res;
  89.  
  90.   if (res==1){
  91.   }
  92.   else if (res==2){
  93.   sum=(sum+10);
  94.   } 
  95.   else if (res==3) {
  96.   printf ( sum (" out of 100\n";
  97.   record();
  98.   exit(1);
  99.   }    
  100.   else
  101.   {  printf ( "You must enter a number between 1 and 3.\n";
  102.   tem2(q, a1, a2);
  103.   }
  104.   return sum;
  105.   }
  106.  
  107.  
  108.   ////////////////////////////////////////////////////////////////////
  109.   // These functions are the questions and answers that are used in //
  110.   // the question template functions.                               // 
  111.   ////////////////////////////////////////////////////////////////////
  112.  
  113.  
  114.  
  115. int q1(char q[60], char a1[20], char a2[20])
  116.   { 
  117.   q="What does the command ls stand for?";
  118.   a1="long";
  119.   a2="list";
  120.   sum = tem2(q, a1, a2);
  121.   return sum;
  122.   }
  123.  
  124.  
  125.  
  126. int q2(char q[60], char a1[20], char a2[20])
  127.   {
  128.   q="What does the cd command stand for";
  129.   a1="Change Directory";
  130.   a2="Choose Definition";
  131.   sum = tem(q, a1, a2);
  132.   return sum;
  133.   }
  134.  
  135.  
  136.  
  137. int q3(char q[60], char a1[20], char a2[20]) 
  138.   {
  139.   q="What does the -l argument stand for with the command ls?";
  140.   a1="level";
  141.   a2="long";
  142.   sum = tem2(q, a1, a2);
  143.   return sum;
  144.   }
  145.  
  146.  
  147.  
  148. int q4(char q[60], char a1[20], char a2[20]) 
  149.   {
  150.   q="What does the cal command display on the screen?";
  151.   a1="Calendar";
  152.   a2="Calculator";
  153.   sum = tem(q, a1, a2);
  154.   return sum;
  155.   }
  156.  
  157.  
  158.  
  159. int q5(char q[60], char a1[20], char a2[20])
  160.   {
  161.   q="What does the cp command stand for?";
  162.   a1="Chop";
  163.   a2="Copy";
  164.   sum = tem2(q, a1, a2);
  165.   return sum;
  166.   }
  167.  
  168.  
  169.  
  170. int q6(char q[60], char a1[20], char a2[20])
  171.   {
  172.   q="What does the rm command stand for?";
  173.   a1="Remove";
  174.   a2="Rename";
  175.   sum = tem(q, a1, a2);
  176.   return sum; 
  177.   }
  178.  
  179.  
  180.  
  181. int q7(char q[60], char a1[20], char a2[20])
  182.   {
  183.   q="What does the pwd command stand for?";
  184.   a1="Password";
  185.   a2="Print Working Directory";
  186.   sum = tem2(q, a1, a2);
  187.   return sum;
  188.   }
  189.  
  190.  
  191.  
  192. int q8(char q[60], char a1[20], char a2[20])
  193.   {
  194.   q="What does the mkdir command stand for?";
  195.   a1="Make Direct";
  196.   a2="Make Directory";
  197.   sum = tem2(q, a1, a2);
  198.   return sum;
  199.   }
  200.  
  201.  
  202.  
  203. int q9(char q[60], char a1[20], char a2[20])
  204.   {
  205.   q="What does the history command print on the screen?";
  206.   a1="Command History";
  207.   a2="Web History";
  208.   sum = tem(q, a1, a2);
  209.   return sum;
  210.   }
  211.  
  212.  
  213.  
  214. int q10(char q[60], char a1[20], char a2[20])
  215.   {
  216.   q="What is the fdisk program";
  217.   a1="Disk Partitioner";
  218.   a2="File Browser";
  219.   sum = tem(q, a1, a2);
  220.   return sum;
  221.   }
  222.  
  223.   ////////////////////////////////////////////////////////////////////
  224.   // This function calculates the date and inputs it and the users  //
  225.   // score into a file called bashquizresults.txt in the same       //
  226.   // direcory as the program                                        // 
  227.   ////////////////////////////////////////////////////////////////////
  228.  
  229.  
  230.   void imran()
  231.   {
  232.   time_t t = time(0);
  233.   tm time = *localtime(&t);
  234.   ofstream results;
  235.   results.open ("q.txt", ios::app);
  236.   results ( "The date of the quiz was " ( time.tm_mday ( '/' ( time.tm_mon + 1 ( '/' (
  237.   time.tm_year + 1900 ( " Your score was " ( sum (" out of 100." "\n";;
  238.   results.close(); 
  239.   }
  240.  
  241.   ////////////////////////////////////////////////////////////////////
  242.   // This function asks the user if they would like to record their //
  243.   // results in a file and calls the function imran()                  //
  244.   //////////////////////////////////////////////////////////////////// 
  245.  
  246.   int record()
  247.   {
  248.   int c;
  249.   printf("\n"("Your score is "( sum ( " out of 100" ( "\n");
  250.   printf( "Would you like to record your results?\n");
  251.   printf ("1) Yes (\n");
  252.   printf ("2) No  (\n");
  253.   scanf ( c;
  254.  
  255.   if (c==1){
  256.   imran();
  257.   printf ( "Your results have been recorded in q.txt in the same directory as this program.\n");
  258.   }
  259.   else if (c==2){
  260.   return 0;
  261.   }
  262.   else {
  263.   printf ( "You must enter either 1 or 2!\n");
  264.   record();
  265.   }
  266.   }
May 21 '10 #1
2 1526
Banfa
9,065 Recognized Expert Moderator Expert
Most of that is already C in fact part from getting rid of the C++ headers and re-writing imran() to use C file handing functions there looks like there is very little to do to me.
May 21 '10 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
C++ code is generally not convertible back to C.

Some C++ syntax does not exist in C. Like templates, classes, inline functions, etc.

Other things in C++ look the same as in C but work differently.

Good luck.
May 21 '10 #3

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

Similar topics

2
1425
by: Stephen Robinson | last post by:
I'm trying to learn Java right now, but I can't figure out exactly what an Applet is. . . Thanks, Stephen,
6
3624
by: What-a-Tool | last post by:
I'm going out out of my mind trying to get this to work with no luck. The error message I get is at the bottom. Can someone please tell me what I'm doing wrong here. I've tried this a million different ways and can't get it to work. I can get it to work with VBScript, but I need to do this project in JavaScript. HELP- PLEASE!? ...
5
3339
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this printer using a RawPrinterHelper class that i found I believe in the msdn. the class works wonderfully when I send stright text data (in the...
15
2669
by: E-Dot | last post by:
I am trying to write a program which asks the user to enter a number in the interval , the program then gives the natural logarithm of that number, using the series for log(x+1)... Here is what I have so far and can't figure out what i'm doing wrong. any help would be greatly appreciated, thanks guys... #include <stdio.h> #include...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.