Thread: Pointer Problem

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    18

    Angry Pointer Problem

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    #define SIZE 4
    
    int main()
    {
    char a[SIZE];
    char *ptrA=a;
    int c[SIZE];
    int count;
    int varify=1;
    
    while(varify==1)
    {
    	//get nums
    	printf("Enter Number for Array\n");
    	
    	for(count=0;count<SIZE;count++)
    	{
    	scanf("%d",&a[count]);
    	}
    	for(count=0;count<SIZE;count++)
    	{
    	c[count]=atoi(ptrA);
    	}
    	for(count=0;count<SIZE;count++)
    	{
    	if(isdigit(c[count])==1)
    	{
    		printf("Must A Numeric Value");
    		varify=1;
    	}
    	else
    	{
    		varify=0;
    	}
    }
    	}
    	//printing
    	printf("Array reads:\n");
    	
    	for(count=0;count<SIZE;count++)
    	{
    		
    		printf("[%d]: %d\n",a[SIZE],a[count]);
    	}
    
    
    
    }
    This is supossed 2 ask a user to enter 4 numbers and accept them as strings. Then it uses error checking using the isdigit lib. function, if the string contains chars, it asks for input again. Then it uses the atoi() to convert strings to integers. Then i still need it to add and print a total. I cant understand how to do all of that.
    THANX if you can help!
    Dave

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: Pointer Problem

    Originally posted by SledMan2002
    This is supossed 2 ask a user to enter 4 numbers and accept them as strings.
    [/B]
    Then why are you doing:

    scanf("%d",&a[count]);

    You should instead be reading a string into a buffer, and then running a check on it character by character to ensure that it's entirely numbers.

    fgets( buf, BUFSIZ, stdio );

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Please don't double post your questions.

    [edit]
    OK, call that triple post, here's another. This one is now closed.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 08:53 PM
  2. Another pointer problem
    By mikahell in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2006, 07:37 PM
  3. Pointer problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2006, 10:21 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. pointer problem
    By DMaxJ in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 12:14 PM