0

Please help me to translate this code from c to c++

#include <stdio.h>
#include <conio.h>

void main()
{
int n,i,j,a[20][20],ok=1,grade=0,aux=0;ok=1;
FILE *f=fopen("c:\graph.txt","r");
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
  for(j=1;j<=n;j++)
     fscanf(f,"%d",&a[i][j]);
fclose(f);

for(i=1;i<=n;i++)
  if(a[1][i]==1) grade++;

for(i=1;i<=n;i++)
 {
  for(j=1;j<=n;j++)
   if(a[i][j]==1) aux++;
  if(aux!=grade) ok=0;
  aux=0;
   }     
if(ok==0) printf("graph is not regular.");
 else printf("graph is regular.");
getch();
clrscr();
}

Edited by andrew12s

5
Contributors
5
Replies
33
Views
4 Years
Discussion Span
Last Post by rubberman
0

Yes, but i still need to translate it to C++.
I'm not into C++ and here I all know is replacing printf with cout and FILE *f=ofpen to ifstream.

0

That, and replace "void main" with "int main" and use cin instead of fscanf. There's nothing else different between C and C++ in that program.

Edited by Ancient Dragon

0

Yes, but i still need to translate it to C++.

Since it's already valid C++ (assuming compiler support for non-portable stuff), you'll need to define what you mean by "C++".

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.