- #1
akueddy
- 14
- 0
Hi guys,
***I just started c programming, I've done some reading last week and i came up with a basic program.Ive got a problem trying to assign an input as an adress to a specified value.Basically i have 3 datas in my array and it will be called by inputting a number which points to the adress.
***Here's the program that i wrote :
#include <stdio.h>
void main()
{
int n;
int Array[3];
Array[0] = 10;
Array[1] = 20;
Array[2] = 30;
int *pArray;
pArray = &Array[n];
printf("choose a number 0-2\n");
scanf("%d", &n);
pArray = &Array[n];
printf("because you choose that number ill give you : $%d\n",*pArray);
}
-------------------------------------------------------------------------------------
***Although there's an error message, the program runs just fine...
C:\Borland\BCC55\Bin>bcc32 pointers4
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
pointers4.cpp:
Warning W8004 pointers4.cpp 16: 'pArray' is assigned a value that is never used
in function main()
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
C:\Borland\BCC55\Bin>pointers4
choose a number 0-2
2
because you choose that number ill give you : $30
C:\Borland\BCC55\Bin>
--------------------------------------------------------------------------------------
***here's my question :
1) Can someone explain to me what's the warning all about and how to correct it? i though i have assign a value for 'pArray' according to the user's input.
2) What if i want to have a really large amount of datas stored in my array, let's say 100 datas. Is there any simple way of doing it say :
Array[10,20,30,40,50,60,70...1000]?
***I just started c programming, I've done some reading last week and i came up with a basic program.Ive got a problem trying to assign an input as an adress to a specified value.Basically i have 3 datas in my array and it will be called by inputting a number which points to the adress.
***Here's the program that i wrote :
#include <stdio.h>
void main()
{
int n;
int Array[3];
Array[0] = 10;
Array[1] = 20;
Array[2] = 30;
int *pArray;
pArray = &Array[n];
printf("choose a number 0-2\n");
scanf("%d", &n);
pArray = &Array[n];
printf("because you choose that number ill give you : $%d\n",*pArray);
}
-------------------------------------------------------------------------------------
***Although there's an error message, the program runs just fine...
C:\Borland\BCC55\Bin>bcc32 pointers4
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
pointers4.cpp:
Warning W8004 pointers4.cpp 16: 'pArray' is assigned a value that is never used
in function main()
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
C:\Borland\BCC55\Bin>pointers4
choose a number 0-2
2
because you choose that number ill give you : $30
C:\Borland\BCC55\Bin>
--------------------------------------------------------------------------------------
***here's my question :
1) Can someone explain to me what's the warning all about and how to correct it? i though i have assign a value for 'pArray' according to the user's input.
2) What if i want to have a really large amount of datas stored in my array, let's say 100 datas. Is there any simple way of doing it say :
Array[10,20,30,40,50,60,70...1000]?