Hi,
I'm only a few days new to C programming as well as programming in general and am trying to write a program that generates a random password that is 2 characters, 3 numbers and 2 characters. I am able to get the output into a printf statement, am not able to get the variables to concatenate into one. I keep getting pointer without a cast errors
What I have so far is below & any help would be greatly appreciated. (I'm using Cygwin, but the target for this will be SCO Unix 7.1 (Unixware) with C.)
Thanks,
Sam
-------------------------------
#include <stdio.h>
#include <time.h>
#include <strings.h>
int main()
{
int p, a, s, w;
int num;
char p1, p2, p3, p4;
char password[7];
srand(time(0));
p = 98 + rand()%25;
p1 = (char)p;
srand(time(0)+1);
a = 98 + rand()%25;
p2 = (char)a;
srand(time(0)+2);
s = 98 + rand()%25;
p3 = (char)s;
srand(time(0)+3);
w = 98 + rand()%25;
p4 = (char)w;
srand(time(0));
num = 100 + rand()%900;
strcpy(password, p1);
strcat(password, p2);
strcat(password, num);
strcat(password, p3);
strcat(password, p4);
printf ("%c%c%d%c%c\n", p1, p2, num, p3, p4); /*testing only, really want output in password variable for use by another program*/
printf ("%c", password);
return 0;
}