Jump to content

How to do this?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
Master

Master

    Newbie

  • Members
  • PipPip
  • 13 posts
hi ,
i want the user to enter a path to save or open a file but i dont know how to do that .. here i just declared another variable named "path" and then palce it in the program ..but no luck ....
well can you help me find out the problem and correct it
i really appreciate your help
thank you
here is the program
//In the name of GOD

#include <iostream.h>

#include <conio.h>

#include <stdio.h>

#include <process.h>

#include <dos.h>

#include <stdlib.h>

#include <fstream.h>

#include <string.h>

FILE *fptr;

struct students{

char   name[36];// students names goes here!

float  grade;// students grades goes here too!

int    classnum;//students class number goes here !

//Total memory accupied by these varibles is 26+6+2=44

	       }st;

  main(){

  int i;

  char path[80];

  clrscr();

   fptr=fopen(path,"w");//There is a document which i want to write data in it.

if (fptr==NULL) { printf("Error: failed to open file\n"); exit(0); }

filebuf(25); //Buffer is Set as to have the same size of acupied memory in order to save the data continuesly.

     gotoxy(25,5);

   cprintf("In the name of god");

   gotoxy(18,7);

   cprintf(" A Master Project");

   gotoxy(10,9);

   printf("Please Enter your path ");

   scanf("%s",path);

   gotoxy(15,12);

   cprintf(" Please Enter the students name,grade and classnumber");

  for (i=0;i<=1;i++){

  scanf("%s",st.name);

  scanf("%f",&st.grade);

  scanf("%d",&st.classnum);

  fwrite(&st,sizeof(st),1,fptr);}

  fclose(fptr);

  return 0;

  }


#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
I only read fast through your code, and the only thing I've to say; you should really try to make your code ANSI-C. What you showed us will not compile on most compilers.

#3
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
If I was you, I would use a downloadable library (OpenGL like GLUT or GLUI) to use a control such as a file or directory selector. In my experience (mostly w/ Python, not as much in C++), using a selector was much easier to use.