forked from portfoliocourses/c-example-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_array_include.c
More file actions
29 lines (26 loc) · 817 Bytes
/
Copy pathinit_array_include.c
File metadata and controls
29 lines (26 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*******************************************************************************
*
* Program: Initialize Array With #include
*
* Description: Example of how to initialize an array with #include in C.
*
* YouTube Lesson: https://www.youtube.com/watch?v=_rr2AgzB8RI
*
* Author: Kevin Browne @ https://portfoliocourses.com
*
*******************************************************************************/
#include <stdio.h>
int main()
{
// initializes the array with the contents of data.txt, which for testing
// purposes was exactly the text:
// 1,2,3,4,5,6,7,8,9,10
int a[2][5] = {
#include "data.txt"
};
// verify array 'a' has been initialized with the values from data.txt
for (int i = 0; i < 2; i++)
for (int j = 0; j < 5; j++)
printf("a[%d][%d]=%d\n",i,j,a[i][j]);
return 0;
}