You've got to be getting tired of this, but: MORE C PROBLEMS!

Hi yet again! This time it’s a madlib. the code is provided below and my problem right now is when I try to compile from Dev-C++ I get… ‘[Linker error] undefined reference to ‘__cpu_features_init’’ and on the next error output line it says ‘Id returned 1 exit status.’ What am I doing wrong this time? thank you…(sorry about all the crap, I don’t know what that is)

[COLOR=#333333]/*
Name: madlib
Author: dreblen
Date: 21/12/2006, 19:06-11
Description: This is a madlib that I made up
*/
#include <time.h>
#include <stdio.h>
void seedrnd(void);
char rnd_color(void);
char rnd_adj(void);
char rnd_thing(void);
char r_col[20];
char r_adj[20];
char r_thing[20];
int main()
{
char name_y[20];
char name_f[20];
char color[20];
char adj[20];
char thing[20];

seedrnd();
rnd_color();
rnd_adj();
rnd_thing();
printf(“Enter your friend’s name: “);
scanf(”%s”,&name_f);
printf(“Enter your name: “);
scanf(”%s”,&name_y);
printf(“Enter a color (all lower-case): “);
scanf(”%s”,&color);
printf(“Ener an adjective (all lower-case): “);
scanf(”%s”,&adj);
printf(“Enter a thing (all lower-case): “);
scanf(”%s”,&thing);

printf("<%s> - You’ll never guess what I saw coming home tonight.
“,name_f);
printf(”<%s> - Was it a %s, %s, %s?
",name_y,adj,color,thing);

if(color==r_col && adj==r_adj && thing==r_thing)
{
printf("<%s> - No way! That’s what it was!
“,name_f);
}
else
{
printf(”<%s> - No, it was a %s, %s, %s.",name_f,r_col,r_adj,r_thing);
}
return(0);
}
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
char rnd_color(void)
{
int random;

random=rand()%10;

switch(random)
{
case 0:
r_col==“green”;
break;
case 1:
r_col==“blue”;
break;
case 2:
r_col==“red”;
break;
case 3:
r_col==“yellow”;
break;
case 4:
r_col==“orange”;
break;
case 5:
r_col==“purple”;
break;
case 6:
r_col==“pink”;
break;
case 7:
r_col==“brown”;
break;
case 8:
r_col==“black”;
break;
case 9:
r_col==“white”;
break;
}
return(r_col[20]);
}
char rnd_adj(void)
{
int random;

random=rand()%10;

switch(random)
{
case 0:
r_adj==“big”;
break;
case 1:
r_adj==“small”;
break;
case 2:
r_adj==“smelly”;
break;
case 3:
r_adj==“hairy”;
break;
case 4:
r_adj==“cuddly”;
break;
case 5:
r_adj==“old”;
break;
case 6:
r_adj==“dirty”;
break;
case 7:
r_adj==“squishy”;
break;
case 8:
r_adj==“sweaty”;
break;
case 9:
r_adj==“creepy”;
break;
}
return(r_adj[20]);
}
char rnd_thing(void)
{
int random;

random=rand()%10;

switch(random)
{
case 0:
r_thing==“dog”;
break;
case 1:
r_thing==“cat”;
break;
case 2:
r_thing==“pig”;
break;
case 3:
r_thing==“man”;
break;
case 4:
r_thing==“woman”;
break;
case 5:
r_thing==“monster”;
break;
case 6:
r_thing==“toad”;
break;
case 7:
r_thing==“dragon”;
break;
case 8:
r_thing==“horse”;
break;
case 9:
r_thing==“snake”;
break;
}
return(r_thing[20]);
}

Very difficult to read with all the color code there.
Maybe you could provide a file?

I’ll upload a file just as soon as I get home, I’m using a library computer at the moment. thank you for a response

Sorry, I guess I don’t know how to upload a *.c file, the attatchment thing only allows pics, I’ll try with just the text again…

 
/*
  Name: madlib
  Author: dreblen
  Date: 21/12/2006, 19:06-11
  Description: This is a madlib that I made up
*/
#include &lt;time.h&gt;
#include &lt;stdio.h&gt;
void seedrnd(void);
char rnd_color(void);
char rnd_adj(void);
char rnd_thing(void);
char r_col[20];
char r_adj[20];
char r_thing[20];
int main()
{
     char name_y[20];
     char name_f[20];
     char color[20];
     char adj[20];
     char thing[20];
 
     seedrnd();
     rnd_color();
     rnd_adj();
     rnd_thing();
     printf("Enter your friend's name: ");
     scanf("%s",&name_f);
     printf("Enter your name: ");
     scanf("%s",&name_y);
     printf("Enter a color (all lower-case): ");
     scanf("%s",&color);
     printf("Ener an adjective (all lower-case): ");
     scanf("%s",&adj);
     printf("Enter a thing (all lower-case): ");
     scanf("%s",&thing);
 
     printf("&lt;%s&gt; - You'll never guess what I saw coming home tonight.
",name_f);
     printf("&lt;%s&gt; - Was it a %s, %s, %s?
",name_y,adj,color,thing);
 
     if(color==r_col && adj==r_adj && thing==r_thing)
     {
          printf("&lt;%s&gt; - No way! That's what it was!
",name_f);
     }
     else
     {
          printf("&lt;%s&gt; - No, it was a %s, %s, %s.",name_f,r_col,r_adj,r_thing);
     }
     return(0);
}
void seedrnd(void)
{
     srand((unsigned)time(NULL));
}
char rnd_color(void)
{
     int random;
 
     random=rand()%10;
 
     switch(random)
     {
          case 0:
               r_col=="green";
               break;
          case 1:
               r_col=="blue";
               break;
          case 2:
               r_col=="red";
               break;
          case 3:
               r_col=="yellow";
               break;
          case 4:
               r_col=="orange";
               break;
          case 5:
               r_col=="purple";
               break;
          case 6:
               r_col=="pink";
               break;
          case 7:
               r_col=="brown";
               break;
          case 8:
               r_col=="black";
               break;
          case 9:
               r_col=="white";
               break;
     }
return(r_col[20]);
}
char rnd_adj(void)
{
     int random;
 
     random=rand()%10;
 
     switch(random)
     {
          case 0:
               r_adj=="big";
               break;
          case 1:
               r_adj=="small";
               break;
          case 2:
               r_adj=="smelly";
               break;
          case 3:
               r_adj=="hairy";
               break;
          case 4:
               r_adj=="cuddly";
               break;
          case 5:
               r_adj=="old";
               break;
          case 6:
               r_adj=="dirty";
               break;
          case 7:
               r_adj=="squishy";
               break;
          case 8:
               r_adj=="sweaty";
               break;
          case 9:
               r_adj=="creepy";
               break;
     }
return(r_adj[20]);
}
char rnd_thing(void)
{
     int random;
 
     random=rand()%10;
 
     switch(random)
     {
         case 0:
              r_thing=="dog";
              break;
         case 1:
              r_thing=="cat";
              break;
         case 2:
              r_thing=="pig";
              break;
         case 3:
              r_thing=="man";
              break;
         case 4:
              r_thing=="woman";
              break;
         case 5:
              r_thing=="monster";
              break;
         case 6:
              r_thing=="toad";
              break;
         case 7:
              r_thing=="dragon";
              break;
         case 8:
              r_thing=="horse";
              break;
         case 9:
              r_thing=="snake";
              break;
     }
return(r_thing[20]);
}

You’ll probably need to include <string.h> and use strcpy() in your switch statements.


/* strcpy() prototype */
char *strcpy(destinationString, sourceString);

/* strcpy() returns a pointer to the destination string
 *
 * example:
 */
strcpy( rthing, "dog");

It worked for me after including stdlib for the srand function

include <stdlib.h>

also try adding a pause at the end so it stays on the screen
system(“pause”);

Don’t you need a default switch case?

Actually, the default case is optional, as are the break statements (although, leaving out breaks in a case will cause it to plow through each case until it does find a break or the end of the block).

Another thing: I suggested above to use strcpy() since the code uses character arrays, but I normally use char pointers in a case like this:


/* code snippet */
int number;
char *zeroOrNot;

number = 1;

if(number)
  zeroOrNot = "Not Zero
";
else
  zeroOrNot = "Zero
";

printf(zeroOrNot);

I’m sorry, I don’t really understand pointers and more advanced stuff

Then it’s about time you learn it…
The statement ’ r_thing==“monster”; ’ does exactly nothing, and i bet your compiler even told you…you probably meant ’ r_thing=“monster”; ’

Btw. don’t forget to free strings when you use strcpy. Welcome to the world of memory leaks…

Good catch! I never noticed the “==” in there. That’s been the problem all along. Of course, now when he changes it he’ll find he needs to use strcpy() or it won’t compile.