this post was submitted on 03 May 2026
1 points (100.0% liked)

techsupport

3135 readers
8 users here now

The Lemmy community will help you with your tech problems and questions about anything here. Do not be shy, we will try to help you.

If something works or if you find a solution to your problem let us know it will be greatly apreciated.

Rules: instance rules + stay on topic

Partnered communities:

You Should Know

Reddit

Software gore

Recommendations

founded 2 years ago
MODERATORS
 

I am just learning arrays and I am experimenting. This one simply won't work. I am trying to have the user define (1) how many elements an int array can hold and (2) what the value of each elements is. The program now outputs random integers. Maybe this isn't even possible, but I'm a complete beginner just playing around for the fun of it. XD

#include <stdio.h>  

int main(void) {  

int scope,elementnr,i,elementvalue,j;  
scope = elementnr = i = elementvalue = j = 0;  
int array[j];  

printf("How many elements should your ARRAY hold: ");  
scanf("%d", &scope);  
getchar();  

for (i = 0; i < scope; ++elementnr, ++i) {  
printf("Enter the value of element number %d: ", elementnr + 1);  
scanf("%d", &elementvalue);  
getchar;  
j = elementvalue;  
}  

printf("You have created an ARRAY that holds %d elements and you have assigned the following values:\n", scope);  

for (i = 0; i < scope; ++i) printf("%d\n",array[j]);  
}  
no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here