this won't compile and i don't know why...

This is a discussion on this won't compile and i don't know why... within the C++ Programming forums, part of the General Programming Boards category; this function is returning this error: Code: q.cpp In function 'int main()': q.cpp:86: cannot convert 'int' to char* for argument ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    63

    this won't compile and i don't know why...

    this function is returning this error:

    Code:
    q.cpp In function 'int main()':
    q.cpp:86:  cannot convert 'int' to char* for argument 1 to insert char*
    I'm trying to be able to scan in a string so that i can use an integer of like 2 numbers for my queue.. as in 10/11/12.. right now i can only use single integer values...

    here is the source:

    Code:
    void insert(char character_to_be_inserted[NAME_LENGTH]) /*************   INSERT  
    ***********************/
    {
      QUEUE_NODE *temp_new_node_pointer;           /* Used to point to a newly 
    created node
                                                      before it is linked into 
    the queue  */
    
      temp_new_node_pointer = (QUEUE_NODE *) malloc(sizeof(QUEUE_NODE));
      temp_new_node_pointer->queued_data[NAME_LENGTH] = character_to_be_inserted[NAME_LENGTH];
    
      if (Q == NULL)                                /* This is the Queue_empty 
    condition */
        {
          Q = temp_new_node_pointer;
          Q->next_in_queue = Q;
        }
      else
        {
          temp_new_node_pointer->next_in_queue = Q->next_in_queue;
          Q->next_in_queue = temp_new_node_pointer;
          Q=temp_new_node_pointer;
        }
    }
    
    main()                          /********************   MAIN   
    ******************************/
    {
    	ios::sync_with_stdio();
      char operators_choice;
    
      do
        {
          printf("\n  Enter choice (lower case is acceptable) --- (I)nsert, 
    (R)emove, or (Q)uit: ");
          fflush(stdout);
          operators_choice=getchar();  getchar();   /* Second getchar just 
    discards the carriage
    						   return used to enter the oeprator's choice  */
    
          switch (operators_choice)
    	{
    	case 'i': case 'I':
              printf("    Enter character to be enqueued:  "); fflush(stdout);
    	  insert(cin.get());
    	  cin.ignore(80,'\n');			  
    	
    	  break;			       /*  return used to enter the enqueued character */
    
    
    	case 'r': case 'R':
    	  if (Q == NULL)
    	    {
    	      printf("    Queue already empty\n"); fflush(stdout);
    	    }
    	  else
    	    {
          	      printf("    The character removed was '%c'\n", 
    removed_from_queue());
    	      fflush(stdout);
    	    }
    	  break;
    
    	default:
    	  if (operators_choice == 'Q' || operators_choice == 'q') break;
    	  printf("\n Please enter your choice of 'I', 'i', 'F', 'f', 'Q', or 'q', 
    only.\n");
    	  fflush(stdout);
    	}
        } while ( !(operators_choice == 'Q' || operators_choice == 'q') );
    }
    i also have my remove function, i'm assuming it still works..

    thanks

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    cin.get() returns an int. You are then passing an int to a function declared as .....

    void insert(char character_to_be_inserted[NAME_LENGTH]);

    That is your problem. You have quite a type mismatch! The function expects a char array which of course is basically a pointer.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21