Pointer problems!

This is a discussion on Pointer problems! within the C Programming forums, part of the General Programming Boards category; 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 ...

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

    Pointer problems!

    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]);
    	}
    
    
    
    }
    I have a problem with the pointer : ptrA. Itz not wanting to work correctly.
    THANX!
    Dave

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    For starters only...:
    Code:
    #define SIZE 4
    char a[SIZE];
    for(count=0;count<SIZE;count++)
    {
    	scanf("%d",&a[count]);
    }
    This is all a bit wrong, I'm afraid. When you use scanf() with %d it needs to read into an int, not a char.

    Can you explain what it is you want your program to do, then someone can guide you better.

    [edit]
    Closed as it was duplicated here.
    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. Problems with passing an array of structures by pointer
    By raptor1770 in forum C Programming
    Replies: 9
    Last Post: 11-29-2008, 10:01 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. base class pointer problems
    By ... in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2003, 10:27 PM

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