Ok if I make a program can I have it print jibberish kinda like it just picks them or even better if you can set it up so that it takes the same characters and just reprints them in a different order, thanks a lot.
Ok if I make a program can I have it print jibberish kinda like it just picks them or even better if you can set it up so that it takes the same characters and just reprints them in a different order, thanks a lot.
-Microsofts Visual C++ Introductory Kit-
Current Projects: Learning Everything C.
Everyone has a photographic memory, some people just don't have any film.
______________________________
When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth
This should give you some random letters.
Code:char randChar = ( rand( ) % 26 ) + 'a'; putc( randChar );
"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers
Ok, could you give me an actual example?(more full I mean) I tried it out with:
Now I have never done this before so I wasn't sure how to do it, how far away from getting this right was I?Code:#include <stdio.h> int main(void) { char randChar = ( rand( ) % 26 ) + 'a'; putc( randChar ); return 0; }
-Microsofts Visual C++ Introductory Kit-
Current Projects: Learning Everything C.
Everyone has a photographic memory, some people just don't have any film.
______________________________
When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth
There isn't really much to it. You do need to seed the random number generator though. TryOriginally posted by CAP
Ok, could you give me an actual example?(more full I mean) I tried it out with:
Now I have never done this before so I wasn't sure how to do it, how far away from getting this right was I?Code:#include <stdio.h> int main(void) { char randChar = ( rand( ) % 26 ) + 'a'; putc( randChar ); return 0; }
Code:#include <stdio.h> #include <time.h> #include <stdlib.h> int main(void) { char randChar; srand( time(NULL) ); randChar = rand( ) % 26 + 'a'; putchar( randChar ); return 0; }
Ack, that was me.
look at this
A good example of what you can do with rand character generation..PHP Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <conio.h>
void showwhirl()
{
int i, j;
char whirl[] = {'|','/','-','\\'};
for (i=0;i<=2; i++)
{
for (j=0; j<=3; j++)
{
printf("%c", whirl[j]);
delay(20);
printf("\b");
}
}
}
void printline(char line[30])
{
int i;
for (i=0; line[i]; i++)
{
showwhirl();
printf("%c", line[i]);
}
}
main()
{
int i;
randomize();
clrscr();
textcolor(LIGHTGREEN);
do
{
for(i=1; i<=40; i++)
{
cprintf("%c ", 49 + rand()%156);
}
delay(rand()%250);
} while (!kbhit());
clrscr();
printline("Programmed By Maharshi Akilla");
printf("\n");
printline("http://mahurshi.tripod.com");
getch();
do
{
} while (!kbhit());
}
COOL PROGRAMS @ www.akilla.tk
What exactly is that supposed to do?
-Microsofts Visual C++ Introductory Kit-
Current Projects: Learning Everything C.
Everyone has a photographic memory, some people just don't have any film.
______________________________
When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth
oops...
that was..
} while (!kbhit());
good luck.
COOL PROGRAMS @ www.akilla.tk
Ok thanks for the quick response I just posted like a min ago but anyways I fixed up the end of the program but there is a major flaw. One of the errors is an unexpected file end but I just put in the end } but then all of these:
'empty character constant
'delay' : undeclared identifier
'randomize' : undeclared identifier
'clrscr' : undeclared identifier
'textcolor' : undeclared identifier
'LIGHTGREEN' : undeclared identifier
I know what the problem with all of these is(except for the empty character one)but in your program I am lost at how to find it, could you please help I am sorry about this but I don't know what is wrong.
Last edited by CAP; 07-11-2002 at 10:58 AM.
-Microsofts Visual C++ Introductory Kit-
Current Projects: Learning Everything C.
Everyone has a photographic memory, some people just don't have any film.
______________________________
When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth
what exactly is that supposed to do ?
did you try running the code ??
it prints random characters on the screen
just like a screen saver (written by a beginner in c)
oops... my above message is not intended for you..
anyway, chances are that your compiler does not
recognize the stuff that i put in my code..
anway, the straight answer to your question has
already been given by people in this post..
the computer generates pseudo random numbers..
to generate random characters, all you have to do
is to generate random numbers which represent
ascii values and then print the characters..
that's what you are doing when you say
printf("%c", 65);
now, you can generate any number between 65 and 65+25
(or a letter between a and z)
by saying
prinf("%c", 65+rand()%26)
the randomize()
function generates random numbers based on current time (this is supposed to generate 'better' random numbers)
the whole point of the code is to show that by generating numbers, you can print them as characters and say "i have generated random characters"
if you want that program to work, try compiling it with a different
compiler... if you want to see how the exe works, go to http://mahurshi.tripod.com/software.htm and see "Matrix Show"
good luck
www.akilla.tk
and by the way, did you include all the required files from my code ??
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dos.h>
#include <conio.h>
if it still doesn't work, it should work with a different compiler (try TC++ 3 if you have... or even Borland C++ 5.5 or something)
Ok, I am a total beginner so thanks for bearing with me. I am using Microsofts Introductory compiler if that makes any difference. Also I did go to your page(I said that above)and the matrix thing is really cool good job. I will try it on a different compiler when I get one(yes I know I can get them from here but I have to go)so anyways I did #include all of the right files and I will try it out later, thanks again.
-Microsofts Visual C++ Introductory Kit-
Current Projects: Learning Everything C.
Everyone has a photographic memory, some people just don't have any film.
______________________________
When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth
I am at nowhere . I(honestly)have a friend who wanted me to make him like a program with all of the 0's and 1's after I showed him a program that kept repeating: Line(whatever line it was)but he didn't want one that simply put 10101001010110 or whatever cause it all looks the same, he wanted one that puts them in random order kinda like your matrix thing but with 0's and 1's, although the matrix one is cool. I don't know if that will help and I am asking cause I don't know how to make random things but I figured that I might as well try, so I hadn't started yet which is why I keep asking questions, sorry all.
-Microsofts Visual C++ Introductory Kit-
Current Projects: Learning Everything C.
Everyone has a photographic memory, some people just don't have any film.
______________________________
When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth
This prints a bunch of 1's and 0's.Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int r, i; srand(time(NULL)); for (i = 0; i < 8; i++) { r = rand() % 2; printf ("%d", r); } return 0; }
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]