Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
convert cpp to c, due to I can't connect to header

#include "prob1.h"
using namespace std;
//just defining of all three structures
struct ProductData
{ 
int ID;
char Name[50];
float Price;
int Quantity;
};

struct CustomerData
{ 
int ID;
char name[50],Address[100],Email[40];
};

struct SalesData
{ 
long ID,ProductID;
long salseamount;
char name[50],Address[100];
char Email[40];
};
int main()
{
ProductData p; // initialize and creating  of Product Data Structures  //assigning the demo values
p.ID=1; //assigning the demo values
p.Price=12,p.Quantity=12;
char x[50]={'R','A','V','I'};
for(int i=0;i<4;i++)
{
p.Name[i]=x[i];
}
cout<<p.ID<<" "<<p.Name<<" "<<p.Price<<" "<<p.Quantity<<"\n";
CustomerData c; // initialize and creating  of Product Data Structures
c.ID=2,c.Email="122";    //assigning the demo values
char y[50]={'A','V','I'};
for(int i=0;i<3;i++)
{
c.name[i]=y[i];
}
char v[50]={'1',' ','s','t','r','e','e','t'};
for(int i=0;i<8;i++)
{
c.Address[i]=v[i];
}
cout<<c.ID<<" "<<c.Email<<" "<<c.name<<" "<<c.Address<<"\n";
SalesData s;// initialize and creating  of Product Data Structures  
s.ID=3,s.ProductID=12,s.salseamount=1234; //assigning the demo values
for(int i=0;i<3;i++)
{
s.name[i]=c.name[i];
}
for(int i=0;i<8;i++)
{
s.Address[i]=c.Address[i]; // (c)Modifying is done by this method so Modifying
}
cout<<s.ID<<" "<<s.ProductID<<" "<<s.salseamount<<" "<<s.name<<" "<<s.Address;
}


What I have tried:

this is the header

#include<stdio.h>
#include<string.h>

struct ProductData
{
    int ID;
    char Name[50];
    float Price;
    int Quantity;
};

struct  CustomerData
{
    int ID;
    char name[50],Address[100],Email[40];
   
};

struct  SalesData
{
    long  ID,ProductID;
    long salesamount;
    char name[50],Address[100];
    char Email[40];

};
Posted
Updated 14-May-23 21:25pm
v2
Comments
Rick York 3-Nov-20 11:39am    
That is not a good reason to convert to C at all.

What does "can't connect to header" mean?
Greg Utas 3-Nov-20 11:47am    
Absolutely useless for OP, but the number of "convert C++ to C" questions on this site is distressing. It makes you wonder what kind of idiots are teaching programming courses when converting in the opposite direction is usually what you want, or should be called upon, to do.

1 solution

All you really need to do is to change all the cout statements to use the C library printf function. Most of the rest is already standard C. But as Rick & Greg already asked, why do you want to do this?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900