Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Does anyone know how to convert C to Visual Basic.net. I have some old code that I want to use in a newer windows form can someone help convert my code???

C#
//Caesar encryptor program
#include <stdio.h>
#include "sys\stat.h"

int main()
{
    int data, output;
    long long int count=0;
    struct stat statbuf;
    char enc_file[260], dec_file[260];
    int shift_phase;
    FILE * sourcefile;
    FILE * destfile;


    printf("\nShift phase: ");
    scanf("%d", &shift_phase);
    printf("\nFile path of target file: ");
    scanf("%s", enc_file);
    printf("\nOutput File Path: ");
    scanf("%s", dec_file);

    if ((sourcefile = fopen(enc_file, "rb"))== NULL)
    {
        printf("\nCan't open target file %s.\n", enc_file);
        return(4);
    }

    fflush(sourcefile);
    fstat(fileno(sourcefile), &statbuf);
    fclose(sourcefile);


    if ((sourcefile = fopen(enc_file, "rb")) == NULL)
    {
        printf("\nCan't open target file %s \n", enc_file);
        return(4);
    }

    if ((destfile=fopen(dec_file,"wb")) == NULL)
    {
        printf("\nCan't open destination file %s \n", dec_file);
        return(4);
    }


    while (count < (statbuf.st_size))
    {
        data=fgetc(sourcefile);
        output=(data+shift_phase);
        fputc(output,destfile);
        count++;
    }

    fclose(sourcefile);
    fclose(destfile);

    return 0;

}
Posted

Well, the C code is actually simple, I guess you may write an equivalent VB.NET method in less than 10 minutes.
:)
 
Share this answer
 
Sure, a lot of people could help you convert your code, but (unless you're lucky) you're not going to get someone to do it for free.

Try Rent A Coder[^] or http://www.codeproject.com/script/Jobs/Edit.aspx[^]
 
Share this answer
 
To be truthful, that is pretty simple c code...it's basically just file io with a shift of the input data. You should be able to do all of that with the System.IO namespace. Just google VB .NET File IO

You just ask for a shift phase, an input file, and an output file.

Then, you open the files, get the file size and go character by character reading from the source, shifting the character and outputting to the output file.

It's all very basic File IO and pretty easy to find with google. If your problem is that you don't understand the C code, then you need to research it. It's pretty easy to do with google.

If you don't understand .Net, then you need to buy some books and read up on it.
 
Share this answer
 

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



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