hey all,

first post of a beginner coder ;),

I keep geting the following error : conflicting types of 'graphic_choice'.. its not a warning so it wont compile. I haven't finished case 7 so that may have some syntax issues.

hope this isn't to big of a code block? i just deleted the contents of the working functions

#include <stdio.h>
#include <stdlib.h>

main()


{
  int menu(); /* function to select option*/
 
  void input_distances(int distance_array[],int num);
  void display_distances(int distance_array[],int num);
  void average_calc(int distance_array[],int num);
  void min_max(int distance_array[],int num);
  void top_three(int distance_array[],int num);
  void converter(int distance_array[],int num);
  void sorted_graphic(int distance_array[],int num);
  void unsorted_graphic(int distance_array[],int num);
  char graphic_choice();

  int input_num_of_drivers();

  float* distances;

  int i;
  int num_drivers, num_of_bytes;
  int option ;
  char x;

  do
  {
    option=menu();

    switch (option)
    {
    case 0:
      break;
    case 1:

      num_drivers=input_num_of_drivers();
      num_of_bytes=num_drivers*sizeof(float);
      distances=malloc(num_of_bytes);

      if ( distances == NULL )
      printf("Cannot Allocate Memory\n");

      input_distances(distances,num_drivers);
      break;

   case 2:
      display_distances(distances,num_drivers);
      break;

    case 3:
    average_calc(distances,num_drivers);
    break;

    case 4:
    min_max(distances,num_drivers);
    break;

    case 5:
    top_three(distances,num_drivers);
    break;

    case 6:
    converter(distances,num_drivers);
    break;

    case 7:
    graphic_choice();

            /*choice = graphic_choice();
            switch (choice)
            {
                case 'y' || 'Y':
                sorted_graphic(distances,num_drivers);
                break;

                case 'n' || 'N':
                unsorted_graphic(distances,num_drivers);
                break;
            }*/
    if ( x == 'y'||'Y')
    sorted_graphic(distances,num_drivers);
    if ( x == 'n'||'N')
    sorted_graphic(distances,num_drivers);
    else
    printf ( "Please select Y or N");

    break;

    }
  }
  while (option!=0);
}
/*free (distance_array);*/
int menu()

/*
Purpose: display menu options
Parameters: none
Returns: a valid option
*/

{
int opt;

  printf ("Press 1 to enter number of drivers and distances\n");
  printf ("Press 2 to display stored information\n");
  printf ("Press 3 to show the average distance\n");
  printf ("Press 4 to show the min / max distances\n");
  printf ("Press 5 to show the three longest distances\n");
  printf ("Press 6 to Convert thedistances to miles\n");
  printf ("Press 7 for a graphical display of the information\n");
  printf ("Press 0 to Exit\n");
  printf("\n");
  printf("Choice:");
  scanf("%d", &opt);
  printf("\n");
return opt;
}

input_num_of_drivers()
{
int num;
    printf( "Enter the number of drivers:" ) ;
    scanf( "%d", &num ) ;
    printf("\n");
return num;
}


void input_distances(int distance_array[],int num)
{

{

}

void average_calc(int distance_array[],int num)
{

}

void min_max(int distance_array[],int num)

{

}

void top_three(int distance_array[],int num)
{

}

void converter(int distance_array[],int num)

{

}

sorted_graphic(int distance_array[],int num)

{
{

unsorted_graphic(int distance_array[],int num)
{

}

graphic_choice( char x )

{

char choice;

    printf(" Would you like the data sorted, Y or N: ");
    scanf("%c", &choice);
/* return choice*/

}

Dani AI

Generated

Quick diagnosis: the "conflicting types" error is coming from mismatches between prototypes and definitions (as noted) and the case‑7 logic has several runtime/logic problems flagged by other replies. Key issues seen in the thread: a prototype/definition mismatch for graphic_choice, calling graphic_choice() without storing its return (so x is uninitialized), incorrect boolean syntax (if (x == 'y' || 'Y') is wrong), inconsistent element types (float *distances vs functions declared to take int arrays), and prototypes declared inside main (old implicit‑int rules can hide type errors). and pointed at signature problems; correctly suggested enabling compiler warnings and checking scanf behavior. Note: the leading space in " %c" is intentional and useful to skip leftover newlines (contrary to ’s implication).

Practical fixes (apply together):

  • Move all prototypes above main, use explicit return types, and make main return int (int main(void) and return 0;).
  • Use consistent types: if distances is float *, change all array parameters to float arr[] or make distances an int *.
  • Define graphic_choice to return a char (no unused parameter) and assign its return to a local variable before branching.
  • Fix the branching logic: either if/else if/else or a switch with separate cases for upper/lower case. Example:
char x = graphic_choice();
switch (x) {
case 'y': case 'Y':
    sorted_graphic(distances, num_drivers);
    break;
case 'n': case 'N':
    unsorted_graphic(distances, num_drivers);
    break;
default:
    printf("Please select Y or N\n");
}

Other recommendations: check scanf return values, use " %c" to skip whitespace, allocate with malloc(num_drivers * sizeof *distances) and test the pointer, free the buffer at program end, and compile with warnings enabled (e.g. gcc -std=c99 -Wall -Wextra) to catch implicit types and uninitialized variables early. These changes will remove the compiler error and fix the case‑7 misbehavior.

Recommended Answers

All 7 Replies

Hi,

line 19 prototype, return type is char, line 172 implementation no return type.

Changed it to return type char and everybody will be happy :)

Welcome to Daniweb.

graphic_choice( char x )

This could be the problem(line 172). Try this

char graphic_choice( char x )

hi, thanks for the reply,

pulling my hair out here over something that should be straightforward..

not sure what u mean though, so my prototype is fine but where do i change my return type in the function?

edit: think its ok, how come i had to put char graphic_choice( char x ), i didn't have to put this in front of any other functions?

Line 162.

sorted_graphic(int distance_array[],int num)
{

}

K guys, the function is good now thanks..

any ideas why it won't return the char?

{
char choice;

    printf(" Would you like the data sorted, Y or N:");
    scanf(" %c", &choice);
    return choice;
}

Output the character before returning, see if it's being read properly.

And see this about your scanf()

edit: think its ok, how come i had to put char graphic_choice( char x ),...

Because you are defining the function as returning a character.

... i didn't have to put this in front of any other functions?

Because your compiler sloppily allows untyped functions to default to integer without warnings. Check your compiler settings and turn more warnings on.

K guys, the function is good now thanks..

any ideas why it won't return the char?

{
char choice;

    printf(" Would you like the data sorted, Y or N:");
    scanf(" %c", &choice);
    return choice;
}

scanf(" %c",&choice) -> You have put a space infront of %c. that could be your problem. scanf is dirty. Avoid using it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.