| | |
erase file and create a random string
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I have some problems:
- How can I erase a file?
- How can I create a random string has 8 letters?
This is my code to create a random string has 8 letters:
But the result is wrong
Thank you!
- How can I erase a file?
- How can I create a random string has 8 letters?
This is my code to create a random string has 8 letters:
C Syntax (Toggle Plain Text)
char *b=""; int i,j; FILE *f=fopen(file,"w"); for(i=0;i<4;i++) { for(j=0;j<7;j++) *b+=char(random(27)+65); fprintf(f,"%s\n",&b); } fclose(f);
Thank you!
One huge problem is pointer b only points to a one-byte empty string which can not be expanded. Since you want a string of 8 characters then you have to allocate memory for it something like this
char b[9] = {0}; . That will allocate memory for 8 characters plus a null terminator, and initialize all of them with 0. Last edited by Ancient Dragon; Nov 4th, 2007 at 9:34 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- VB 6.0. Creating a file for random access (Visual Basic 4 / 5 / 6)
- random string (C)
- search pattern in a file and create dictionary as you search (Python)
- Cygwin file generator (C)
- File.Create Question (C#)
- Function that creates random changes in a string?? (Python)
Other Threads in the C Forum
- Previous Thread: BASIC Editor: Where Did I Go Wrong?
- Next Thread: include exe in filehandling
| Thread Tools | Search this Thread |
#include adobe ansi api append array arrays asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork framework frequency function getlasterror givemetehcodez global grade gtkgcurlcompiling hacking hardware highest histogram include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scripting segmentationfault sequential socket socketprograming standard string systemcall testing threads turboc unix user voidmain() wab windows.h windowsapi






