Jump to content

how to convert this C function into C-Sharp ?

- - - - -

  • Please log in to reply
No replies to this topic

#1
serendipity1276

serendipity1276

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,

Can any C-Sharp expert out there convert the C function below, into
C-Sharp code, that I can insert into an already-existing C-Sharp program, that will compile? Thanks.

I have an existing C code that compiles in the C environment. I want to insert this function into an already running C-Sharp program. Because I only have less than a week to get this done, learning C-Sharp at this time is not practical.

The C function is simple:

a) get the output of the ipconfig /all command, write it into a tmp file
b) read that file for the string "gateway.net" or for anything string
that contains the string "192.168.1"
c) if this is found, set found = 1
d) when done, delete the tmp file
e) if found == 0, stop the program

Below is that C function.


Check ( )

{
char str [100];
int found = 0;

FILE *fi;

system ("ipconfig /all > c:\\temp\\tmp_file");

fi = fopen ("c:\\temp\\tmp_file", "r");

while (! feof (fi))
{
fscanf (fi, "%s", str);

if ((strcmp (str, "gateway.net") == 0) || (strstr (str, "192.168.1") != NULL))
found = 1;
}

fclose (fi);

remove ("c:\\temp\\tmp_file");

if (found == 0)
exit (0);

return 0;
}




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users