473,326 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Opening and outputting a text file

Hi everyone,

I want to open a .txt file and just show it.Not for reading or anything but just showing it when people enter a certain number.
Can anyone tell me how to do this?

and is there a command to close all windows of the application?

IM DOING C++ IN BORLAND
Dec 4 '06 #1
12 3521
sicarie
4,677 Expert Mod 4TB
Hi everyone,

I want to open a .txt file and just show it.Not for reading or anything but just showing it when people enter a certain number.
Can anyone tell me how to do this?

and is there a command to close all windows of the application?

IM DOING C++ IN BORLAND
Transmit -

This will help you open a file, read stuff in, and then you can print it out to the screen:

http://www.cplusplus.com/doc/tutorial/files.html

You could use a case (switch) statement in a while loop for the user input and when to display, if you need help on that, check out thescripts.com's tutorial:

http://www.thescripts.com/serverside...ops/index.html

That should get you started!
Dec 4 '06 #2
Thanks, but I actually meant opening the .txt file like when you would double click on it.
Sorry if I didn't explain well!

and do you know how to close the whole program? I tried abort() but that didn't gave me what I wanted!

thx already!!
Dec 4 '06 #3
sicarie
4,677 Expert Mod 4TB
Thanks, but I actually meant opening the .txt file like when you would double click on it.
Sorry if I didn't explain well!

and do you know how to close the whole program? I tried abort() but that didn't gave me what I wanted!

thx already!!
I would guess you are using Windows, and I'm not entirely sure how to open it like that - as it involves a system command to open Word/TextPad/Notepad to open the file up... You can always just open it yourself and print it on the screen (unless you want someone to be able to edit it...). But that shouldn't be too hard to google and find out - I would guess it uses 'windows.h' to run whatever the executable is, and possibly send the file as a parameter? I'm not a windows guy, so I'm not too sure... (sorry!)

You can end the program through return 1 or return 0;
Dec 4 '06 #4
Ganon11
3,652 Expert 2GB
I know how to open it - just pass the system() function a string that has the path to the file you want to open, i.e.

Expand|Select|Wrap|Line Numbers
  1. system("C:\\My Documents\\My Folder\\MyFile.txt"); // Double slashes needed because \\ is escape character for \
The system() function takes a string and performs operations just like your regular MSDOS-style command prompt would with the same string. For instance, if I wanted to display the files listed in the folder with my program, I could use the command

Expand|Select|Wrap|Line Numbers
  1. system("DIR");
because dir is the command I use in MSDOS to do the same thing.

Closing the file, though...I don't know.
Dec 4 '06 #5
sicarie
4,677 Expert Mod 4TB
I know how to open it - just pass the system() function a string that has the path to the file you want to open, i.e.

Expand|Select|Wrap|Line Numbers
  1. system("C:\\My Documents\\My Folder\\MyFile.txt"); // Double slashes needed because \\ is escape character for \
The system() function takes a string and performs operations just like your regular MSDOS-style command prompt would with the same string. For instance, if I wanted to display the files listed in the folder with my program, I could use the command

Expand|Select|Wrap|Line Numbers
  1. system("DIR");
because dir is the command I use in MSDOS to do the same thing.

Closing the file, though...I don't know.

Thanks, Ganon11 - I knew there was a way to do it, but wasn't entirely sure how. And I'm pretty sure whatever user who this file is displayed to is going to have to be in charge of closing it.
Dec 4 '06 #6
I put this:
system("C:\\School\\Gestructureerd programmeren\\Programmeerproject\\HandleidingC.txt ");

and it gave me this error:
linking error: undefined symbol _system in module simon.C

any thoughts?
Dec 5 '06 #7
sorry for double post but the 5 minutes expired:

I put the code I just put above ^^ in a switch case statement

so it would look like this:

switch(keuze){
case 1:
system("pathto.txtfile");
break;
case 2:
...
}

I guess that's totally wrong :D Can you specify how to do it a bit more? Thanks man you're being a great help!!!

appreciate it!
Dec 5 '06 #8
sicarie
4,677 Expert Mod 4TB
sorry for double post but the 5 minutes expired:

I put the code I just put above ^^ in a switch case statement

so it would look like this:

switch(keuze){
case 1:
system("pathto.txtfile");
break;
case 2:
...
}

I guess that's totally wrong :D Can you specify how to do it a bit more? Thanks man you're being a great help!!!

appreciate it!
Can you post the entire program?
Dec 5 '06 #9
willakawill
1,646 1GB
sorry for double post but the 5 minutes expired:

I put the code I just put above ^^ in a switch case statement

so it would look like this:

switch(keuze){
case 1:
system("pathto.txtfile");
break;
case 2:
...
}

I guess that's totally wrong :D Can you specify how to do it a bit more? Thanks man you're being a great help!!!

appreciate it!
do you have this at the top of your file;
Expand|Select|Wrap|Line Numbers
  1. #include "stdlib.h"
Dec 5 '06 #10
well the program is kinda big and yes I typed:

#include <stdlib.h>

on top!
Dec 5 '06 #11
sicarie
4,677 Expert Mod 4TB
well the program is kinda big and yes I typed:

#include <stdlib.h>

on top!
How big is "kinda big"? We need more to be able to figure this out. If I wrote what I thought was in your code before/after/in the switch statement, I'm pretty sure it would be a completely different program. The entire error message would help too.
Dec 5 '06 #12
Here you are then:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h> /*nodig voor random()*/
  3. #include <time.h> /*gaat ermee voor zorgen dat niet telkens dezelfde getallen worden opgeroepen*/
  4. #include <windows.h>
  5.  
  6. int welkomtekst(void);
  7. int keuze1(void);
  8. int startspel(void);
  9. int moeilijkheidsgraad(void);
  10. int highscores(void);
  11. int eerstekeeropgestart = 0;
  12. int aantalgetallen = 1;
  13. int highscore = 0;
  14. int moeilijkheid = 1;
  15.  
  16. int main(void){
  17.     int keuze;
  18.     int adminnaam;
  19.     int adminpaswoord;
  20.     int system(const char *handleiding);
  21.  
  22.     fflush(stdin);
  23.     aantalgetallen = 1;
  24.     highscore = 0;
  25.     clrscr();
  26.  
  27.     if(eerstekeeropgestart != 1){
  28.         printf("Omdat dit de eerste keer is dat SIMON wordt opgestart,\nmoet er een administrator naam en paswoord ingegeven worden\n\n\n");
  29.         printf("Geef de administrator naam in: ");
  30.         scanf("%d",&adminnaam);
  31.         printf("Geef het administrator paswoord in: ");
  32.         scanf("%d",&adminpaswoord);
  33.  
  34.         eerstekeeropgestart = 1;
  35.         main();
  36.     }
  37.  
  38.     printf("Welkom bij Simon!\n\n");
  39.     welkomtekst();
  40.     scanf("%d",&keuze);
  41.     switch(keuze){
  42.         case 1 :
  43.             clrscr();
  44.             keuze1();
  45.             break;
  46.         case 2:
  47.             moeilijkheidsgraad();
  48.             break;
  49.         case 3:
  50.             break;
  51.         case 4:
  52.             break;
  53.         case 5:
  54.             highscores();
  55.             break;
  56.         case 6:
  57.             break;
  58.         case 7:
  59.             abort();
  60.             break;
  61.         default:
  62.             printf("Foutieve ingave");
  63.             main();
  64.             break;
  65.     }
  66.     return 0;
  67. }
  68.  
  69. int welkomtekst(void){
  70.     clrscr();
  71.  
  72.     printf("|-----------------------------------\n");
  73.     printf("|Spel gemaakt door Vandersteegen Jan\n");
  74.     printf("|-----------------------------------\n\n");
  75.  
  76.     printf("|------------------------------------------\n");
  77.     printf("| [][][]  °°  [][][][]  [][][]  [][]    [] \n");
  78.     printf("| []      []  [] [] []  []  []  [] []   [] \n");
  79.     printf("| [][][]  []  []    []  []  []  []   [] [] \n");
  80.     printf("|     []  []  []    []  []  []  []    |][] \n");
  81.     printf("| [][][]  []  []    []  [][][]  []      [] \n");
  82.     printf("|------------------------------------------\n\n");
  83.     printf("Maak een keuze uit de volgende mogelijkheden: \n\n");
  84.  
  85.     printf("******************************\n");
  86.     printf("1: Nieuw spel \n");
  87.     printf("2: Moelijkheidsgraad kiezen \n");
  88.     printf("3: Herhaling \n");
  89.     printf("4: Handleiding \n");
  90.     printf("5: Highscores inkijken \n");
  91.     printf("6: Inloggen als administrator\n");
  92.     printf("7: Programma afsluiten \n");
  93.     printf("******************************\n\n");
  94.  
  95.     printf("Uw keuze: ");
  96.     return 0;
  97. }
  98.  
  99. void sleep(unsigned int mseconds){ /*Wordt gebruikt om te wachten bij het genereren van nieuwe getallen*/
  100.      clock_t goal = mseconds + clock();
  101.      while (goal > clock());
  102. }
  103.  
  104. int highscores(void){
  105.      char gedrukt;
  106.      clrscr();
  107.      fflush(stdin);
  108.      printf("Druk op 'X' om terug naar het hoofdmenu te gaan: ");
  109.      scanf("%c",&gedrukt);
  110.      if ((gedrukt == 'x')||(gedrukt =='X')){
  111.          main();
  112.      }else{
  113.          highscores();
  114.      }
  115. }
  116. int handleiding(void){
  117.  
  118. }
  119. int moeilijkheidsgraad(void){
  120.      clrscr();
  121.      fflush(stdin);
  122.      printf("INFO: Kijk in de handleiding voor de verschillen tussen de moeilijkheidsgraden\n\n");
  123.      printf("Kies hier de moeilijkheidsgraad: \n\n");
  124.      printf("1: Makkelijk\n");
  125.      printf("2: Gewoon\n");
  126.      printf("3: Moeilijk\n");
  127.      printf("4: Superman stijl\n\n");
  128.      printf("Uw keuze: ");
  129.      scanf("%d",&moeilijkheid);
  130.      printf("Keuze geregistreerd!\nU wordt binnen enkele seconden terug verwezen naar het hoofdmenu!\n");
  131.      sleep(2500);
  132.      fflush(stdin);
  133.      main();
  134. }
  135. int keuze1(void){
  136.      char enter;
  137.  
  138.      fflush(stdin);
  139.  
  140.      printf("*** LET THE GAMES BEGIN ***\n\n");
  141.      printf("U kan terug naar het hoofdmenu gaan door op 'X' te duwen\n\n");
  142.      printf("Druk op ENTER als u klaar bent om te starten\n\n");
  143.      scanf("%c",&enter);
  144.      if(enter == '\n'){
  145.       printf("HOU U KLAAR WANT BINNEN 2 SECONDEN START HET SPEL !!!");
  146.       sleep(2000);
  147.       startspel();
  148.      }else{
  149.         if ((enter == 'x')||(enter =='X')){
  150.          main();
  151.         }
  152.         printf("\nFoutieve invoer! Druk op ENTER of op X\n\n");
  153.         keuze1();
  154.      }
  155.      return 0;
  156. }
  157.  
  158. int startspel(void){
  159.      int t = 0;
  160.      int tabel1[25] = {0};
  161.      int tabel2[25] = {0};
  162.      int randomgetal;
  163.      int keuze;
  164.      int aantalgoed = 0;
  165.  
  166.      aantalgetallen++;
  167.  
  168.      srand(time(NULL));   /*zorgt ervoor dat niet altijd dezelfde random getallen gegenereert worden*/
  169.      sleep(500);
  170.      for(t=0;t<=aantalgetallen;t++){
  171.         clrscr();
  172.         randomgetal = rand()%5;
  173.         tabel1[t] = randomgetal;
  174.         printf("Druk op X om terug te gaan naar het hoofdmenu\n\n");
  175.         printf("%de na te typen getal: ",t+1);
  176.         printf("%i \n",randomgetal);
  177.         tabel1[t] = randomgetal;
  178.         switch(moeilijkheid){
  179.             case 1:
  180.                 sleep(1000);
  181.             case 2:
  182.                 sleep(750);
  183.             case 3:
  184.                 sleep(500);
  185.             case 4:
  186.                 sleep(200);
  187.         }
  188.      }
  189.      for(t=0;t<=aantalgetallen;t++){
  190.         clrscr();
  191.         printf("Druk op X om terug te gaan naar het hoofdmenu\n\n");
  192.         printf("*-*-* Uw score is: %d *-*-* \n\n",highscore);
  193.         printf("Typ het %de getoonde getal: ",t+1);
  194.         scanf("%d",&tabel2[t]);
  195.         if(tabel2[t] != tabel1[t]){
  196.             fflush(stdin);
  197.             printf("\n FOUT - GAME OVER!\n\n");
  198.             printf("Wat wilt u doen?\n");
  199.             printf("1: Een nieuw spel starten\n");
  200.             printf("2: Terug naar het hoofdmenu\n");
  201.             printf("3: Highscores bekijken\n");
  202.             printf("4: Moeilijkheidsgraad veranderen\n");
  203.             printf("Uw keuze: ");
  204.             scanf("%d",&keuze);
  205.             switch(keuze){
  206.                 case 1 :
  207.                     clrscr();
  208.                     aantalgetallen = 1;
  209.                     highscore = 0;
  210.                     keuze1();
  211.                     break;
  212.                 case 2:
  213.                     main();
  214.                     break;
  215.                 case 3:
  216.                     printf("Nog niet klaar");
  217.                     break;
  218.                 case 4:
  219.                     moeilijkheidsgraad();
  220.                     break;
  221.                 default:
  222.                     printf("Foutieve invoer: U wordt binnen een paar seconden naar het hoofdmenu gebracht");
  223.                     sleep(1500);
  224.                     main();
  225.             }
  226.         }else{
  227.             highscore+=100;
  228.             aantalgoed++;
  229.             if (aantalgoed == (aantalgetallen + 1)){
  230.                 startspel();
  231.             }
  232.         }
  233.      }
  234. }
Dec 5 '06 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Marcus | last post by:
I am using the following command to open a query in Excel: DoCmd.OutputTo acOutputQuery, "qryTest", acFormatXLS, , True The problem is that the code creates an Excel 97 file. Is there a way...
5
by: Andrei Pociu | last post by:
I have a major doubt about outputting text in ASP .NET when using code behind. I know most of the output you gain from a code behind file (.aspx.cs) is outputted to the Webform (.aspx) using...
21
by: Sender | last post by:
I have two questions: (1) I just want to check whether a .txt file is empty or not (without opening it). Like I click on a command button then it should give message EMPTY if is empty and show...
5
by: Ash Phillips | last post by:
Ok, I'm not sure how I can explain this but here goes. I have this program that uses a ListView for entries. What I have the program doing is taking all the items from the listview, and writing...
11
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
5
by: phong.lee | last post by:
Hello all, I was wondering if someone can assist me in outputting 6 reports into a pdf file? I created a macro that generates the 6 reports and right now it's saved as a snapshot on my drive. ...
3
by: mohaakilla51 | last post by:
Alright guys, I am working on a flashcard script... Previously I had it so that it onlty had predefined categories. People were complaining, so now I am trying to make it to where it reads...
12
by: billelev | last post by:
This is probably a very easy question to answer: I have been outputting some text to a message box, similar to the following: strOutput = "---" & Chr(10) & Chr(10) strOutput = strOutput &...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.