Thread: Incompatible types in assignment.

  1. #31
    Registered User
    Join Date
    Nov 2008
    Posts
    44
    If i did:
    Code:
    while( )
    {
    	for( i = 0 ; i < 15 && ( num[i] = getchar() ) != '.' ; i++ )
    		num[i] = getchar() ;
    	q = insertnumber( *num, q ) ;
    }
    surely there needs to be a loop there otherwise it will only take on phone number then stop.

  2. #32
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    alright so if I understand you correctly here's an updated version using the while loop.
    here loop breaks on end of file; else store input in num until a full stop or out of bounds.
    Code:
    int check, i = 0;
    while ((check = getchar()) != EOF)
    {
        if (check != '.' && i < 15)
            num[i++] = check;
        else
            q = insertnumber(*num, q) ;
    }
    question is what you would do if input has 10 chars only, would you still create a linked list node or break out of the program?
    Last edited by itCbitC; 12-22-2008 at 11:39 AM.

  3. #33
    Registered User
    Join Date
    Nov 2008
    Posts
    44
    I'll check your loop out in a sec. Currently im using.

    Code:
    while( num[0] != '.' )
    	{
    		scanf( "%15s", num ) ;
    		if( num[0] != '.' )
    			q = insertnumber( *num, q ) ;
    		else
    			break ;
    	}
    Would that work?

  4. #34
    Registered User
    Join Date
    Nov 2008
    Posts
    44
    As far as i can see with your loop it wont terminate at a full stop.

  5. #35
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Depends what you're looking for in your code, which will exit out only if the first char num[0] is a period but not if the period is in the middle like num[10].
    Last edited by itCbitC; 12-22-2008 at 11:54 AM.

  6. #36
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by killpoppop View Post
    As far as i can see with your loop it wont terminate at a full stop.
    Correct it will terminate only on EOF and IINM a full stop is the terminal condition for node creation ie when you see a period you invoke insertnumber()??

  7. #37
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    From what I have seen, I recommend something like this right now.

    Code:
    int maybe;
    unsigned area, prefix, exchange;
    char num[15];
    
    maybe = scanf("(%3u)%3u-%4u", &area, &prefix, &exchange);
    while (maybe == 3) {
       sprintf(num, "(%u)%u-%u", area, prefix, exchange);
       insertnumber(num, q);
       maybe = scanf("(%3u)%3u-%4u", &area, &prefix, &exchange);
    }
    
    if (scanf("%c", &maybe) == 1 && maybe == '.') {
       /**success, else do failure operations. **/
    }
    It might not be perfect, but you need a coordinated approach to input right now. Given that a full stop is the sentinel value for a loop, we need to do a priming read. If the priming read is successful, then we enter the loop, and only exit the loop when a read fails.

    When the read does fail, we have to read the next character to determine if the reads were successful. For consistency this is done with scanf. I believe the rest is self explanatory. It should be easy enough to code the logical inverse if you only need to do something when the loop fails to read all the input.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. assignment from incompatible pointer types
    By iunah in forum C Programming
    Replies: 13
    Last Post: 10-12-2008, 03:32 AM
  2. incompatible types in assignment
    By vapanchamukhi in forum C Programming
    Replies: 6
    Last Post: 09-19-2008, 07:45 AM
  3. incompatible types in assignment
    By vapanchamukhi in forum C Programming
    Replies: 1
    Last Post: 09-18-2008, 11:35 PM
  4. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  5. Incompatible types in assignment error
    By Zildjian in forum C Programming
    Replies: 12
    Last Post: 10-03-2003, 01:15 PM