473,327 Members | 2,012 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,327 software developers and data experts.

[C] printing a variable to a txt file *help*

hello everyone, i'm just a bit stuck on what to do for this, heres my code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <windows.h>
  3.  
  4. int main(int argc, char **argv)
  5.    unsigned char c;
  6.    unsigned char g;
  7.    int a;
  8.    int d;
  9.    int e = 40;
  10.    int f = 1;
  11.    int length; 
  12.  
  13.    srand(GetTickCount());
  14.  
  15.    printf("\t\tPassword Generator\n\n");
  16.    printf("Options:\n\n"
  17.           "1 - Generate a password\n"
  18.           "2 - Exit\n\n"
  19.           ">");
  20.  
  21.    a = getchar();       
  22.    if (a == '1')
  23.    {
  24.       for (d = 0; d < e; d = d + f)
  25.       {
  26.        c = (rand() % 255);
  27.        if(isgraph(c))
  28.         {              
  29.           printf("%c", c);
  30.         }
  31.       }
  32.       printf("\n\n");
  33.  
  34.    }
  35.    if (a == '2')
  36.    {
  37.       exit(1);
  38.    }   
  39.    system("pause");
  40.    return 0;
  41. }
this is a password generator i coded but, i've got it to generate a password after the users inputs the number "1", but i'm stuck on figuring out, how i would print that string that is generated to a chosen text file. currently the random string prints to the console but i need to print it to a text file so that its stored easily.

any help is appreciated, thanks.
Jul 1 '07 #1
5 1634
niskin
109 100+
Expand|Select|Wrap|Line Numbers
  1. FILE *fp;
  2. fp=fopen("file.txt");
  3. fprintf(fp, <variable-storing-password>);
  4. fclose(fp);
Jul 1 '07 #2
thanks for your quick response, i added those statements and i seem to be getting a compiling error that im not familiar with :s

[Warning] passing arg 2 of `fprintf' makes pointer from integer without a cast
the error is on line 37.

here is my source:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <windows.h>
  3.  
  4. int main(int argc, char **argv)
  5. {
  6.    unsigned char c;
  7.    unsigned char g;
  8.    int a;
  9.    int d;
  10.    int e = 40;
  11.    int f = 1;
  12.    int length; 
  13.  
  14.    srand(GetTickCount());
  15.  
  16.    printf("\t\t[JockNet] Password Generator\n\n");
  17.    printf("Options:\n\n"
  18.           "1 - Generate a password\n"
  19.           "2 - Exit\n\n"
  20.           ">");
  21.  
  22.    a = getchar();       
  23.    if (a == '1')
  24.    {
  25.       for (d = 0; d < e; d = d + f)
  26.       {
  27.        c = (rand() % 255);
  28.        if(isgraph(c))
  29.         {              
  30.           printf("%c", c);
  31.         }
  32.       }
  33.       printf("\n\n");
  34.  
  35.       FILE *fp;
  36.       fp = fopen("passwords.txt", "w");
  37.       fprintf(fp, c);
  38.       fclose(fp);  
  39.    }
  40.    if (a == '2')
  41.    {
  42.       exit(1);
  43.    }   
  44.    system("pause");
  45.    return 0;
  46. }
sorry to bother you again, thanks.
Jul 1 '07 #3
niskin
109 100+
What does the error say?
Jul 1 '07 #4
[Warning] passing arg 2 of `fprintf' makes pointer from integer without a cast

i posted it in the above post, in a quote.

edit : im using dev-cpp as my IDE if that helps.
Jul 1 '07 #5
niskin
109 100+
Try making "c" a char array.
Jul 1 '07 #6

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

Similar topics

0
by: DotNetDummy | last post by:
Hi all, I am trying to set the printing setting e.g duplex mode etc. on a default printer when I.E object started printing a particular html doc. Here's the partial code, any help would be...
1
by: NickB | last post by:
Please could someone tell me what is wrong. Ther error is: An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll Additional information: Object...
1
by: G.Esmeijer | last post by:
Friends, I'm (a bit) dissapointed about the printing possibilities in c#. It could also be lack of knowedge. I would like to align a text on the right side of the paper when printing. For...
4
by: Al Jones | last post by:
Well, hopefully that title get someones attention. In this old gwbasic program I've converted I *have* sucessuflly converted it to print to a file and the output is acceptable. From there I have...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
0
by: Galen Somerville | last post by:
In VB6 (converted to VB2005) there are 6 different sub-menu items where the user has a choice of listing items on the screen or printing out a list of items. Each such menu item puts the name of...
6
by: Siv | last post by:
Hi, I am getting into printing with VB.NET 2005 and want to implement the usual capability that a user can select a selection of pages. I have a report that is generated by my application that if...
4
by: Lucas Ponzo | last post by:
Hi All, I have an ASP.NET 2.0 app. The users access the pages, uniquely via pocket pc ... I need to print a page. But I need that the page print on a printer installed on the web server...
6
by: sheinaz | last post by:
Hi I am tryign to use this to print my table in landscape by default. i am new at the xsl and need some assistance. when i try to use the following i get the error: Cannot view XML input using...
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.