dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: how to convert this C function into C-Sharp?

  1. #1
    Join Date
    Aug 2011
    Posts
    2

    how to convert this C function into C-Sharp?

    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;
    }

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,337

    Re: how to convert this C function into C-Sharp?

    I would think you should be able to learn enough C# to do this in very little time, especially if you already know C/C++. All you have there is starting a process with parameters, basic File function and basic String function. Should be pretty simple.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)