Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

make the following code work on LINUX: include <windows.h> #include <string> #in

ID: 3740268 • Letter: M

Question

make the following code work on LINUX:

include <windows.h>
#include <string>
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <dir.h>
#include <unistd.h>
using namespace std;


std::string current_working_directory()
{
    char working_directory[MAX_PATH+1] ;
    GetCurrentDirectoryA( sizeof(working_directory), working_directory ) ;
    return working_directory ;
}
int main(void)
{
int i,j;
   for(i=1;i<=2;i++)
   {  
    if (mkdir("working_directorydiri",0777)==-1);
       {
       cerr<<"Error : "<<strerror(errno)<<endl;
       exit(1);
       }
   else
       {
       cout << "Please enter j value: ";
       cin >> j;

        ofstream write ("working_directorydiri ilej.txt");
       if (write.is_open())
           {
           write << "This is a new file."<<endl;
           write.close();
           }
       else
           cout << "Unable to open file";
       }
       if (j==20)
       int symlink(const char *filej, const char *link1)
  
   }
   ofstream write ("working_directory ile1.txt");
       if (write.is_open())
       {
           write << "This is the first file."<<endl;
           write.close();
       }
       else
           cout << "Unable to open file";
return 0;
}

Explanation / Answer

The problem is you don't define the symlink function you just called it in if(j==20) condition

For executing program in linux

Follow steps

Step 1. Use a text editor to create the C source code.

Type the command

gedit hello.c

and enter the C source code below:

#include <stdio.h>

main() {

printf("Hello World ");

}

Close the editor window.

Step 2. Compile the program.

Type the command

gcc -o hello hello.c

This command will invoke the GNU C compiler to compile the file hello.c and output (-o)

the result to an executable called hello.

Step 3. Execute the program.

Type the command

./hello

This should result in the output

Hello World