Sponsored Content
Top Forums Programming Looping through multiple arrays in C. Post 303021242 by Azrael on Tuesday 7th of August 2018 06:51:07 AM
Old 08-07-2018
Looping through multiple arrays in C.

Not sure if this is possible, but I've tried this about a thousand ways now. I am making something with a lot of arrays. I thought I could put the array names into a separate array and then loop through them to call all of their elements. This is the best I've got so far:

Code:
#include <stdio.h>
#include <stdlib.h>

int main() {

	char c;

	int a [5] = {1,2,3,4,5};
	int b [5] = {6,7,8,9,10};

	for(c = 'a'; c <= 'b'; ++c) {
		for (int j = 0; j < 5; j++){
			printf("%d\n", c[j]);
		}
	}
}

From it I get the following error:
Code:
$ gcc canloop.c -o canloop
canloop.c: In function ‘main':
canloop.c:17:20: error: subscripted value is neither array nor pointer nor vector
    printf("%d\n", c[j]);

Oddly enough it still runs despite the error:
Code:
$ ./canloop 
0
1
2
3
4
0
1
2
3
4

Seems its not incrementing on the first loop with c. I've tried changing ++c to c++, casting, etc, but no change. Anyone know if this is not possible, some way to do this better or what I may be missing?
This User Gave Thanks to Azrael For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

multiple arrays through awk...

i am v new to awk, well unix as a whole really but im enjoying it alot... im trying to extract some data from a file, and parsing it into arrays, ive trawled for hours on the internet and cant find much when it comes to awk and arrays?? anyway, heres the file: tableA tableB tableC ... (2 Replies)
Discussion started by: newbeenie
2 Replies

2. Shell Programming and Scripting

Read multiple arrays in mysql

I have a database that include 5 tables, and they are related to each other through foreign key relations. The root is called colleges. There are multiple colleges, and each college has 1+ departments, each department has 1+ IT stuff, each IT stuff owns 1+ IP addresses. I have designed the database... (0 Replies)
Discussion started by: pinkgladiator
0 Replies

3. UNIX for Dummies Questions & Answers

Help in Array looping and creating multiple lines

hi Gurus, I'm a newbie in scripting please check my script if this is correct. I think there's something wrong with it but I;m not sure. I'm trying to create multiple lines using awk from external xml files but i want to add additonal info in the data manually Since i don't knwo how to... (0 Replies)
Discussion started by: sexyTrojan
0 Replies

4. Shell Programming and Scripting

multiple looping with case and funtion showing error, Please help

Hello All, I have code as follows :- while true do {opening a case1 statement} 1) {opening another case2 statement} {closing case 2} 2) Showing error for "2)" as Syntax error at line 59 : `)' is not expected. *) {closing case 1} ... (5 Replies)
Discussion started by: Renjesh
5 Replies

5. Shell Programming and Scripting

Looping for multiple directories

Hi experts, I am totally stuck with this. I run a looping "for" command for multiple directories, manually, I have done this : vfor dir in A B; do cp -p $dir/X.txt X-${dir}.txt done where A and B is directory name. However, I need to run for many directories. So I have tried this :... (7 Replies)
Discussion started by: guns
7 Replies

6. Shell Programming and Scripting

Looping through arrays

i just started learning arrays and found this example on the net: for (( i = 0 ; i < ${#names} ; i++ )) do echo ${names} done However, even though I can echo ${#names} I am unable to get the increment to work. I have tried eliminating spaces and changing brackets and nothing seems... (4 Replies)
Discussion started by: newbie2010
4 Replies

7. Shell Programming and Scripting

Looping all subdierctories in multiple pipes

Hello friends, I want to run this code on every document in every sub-directory. tr -d '\n' < MulitpleInput.txt | awk '{gsub(/\. /,".\n");print}' | grep “\ I tried several looping techniques but couldn't get it to run in this example. Any ideas? Thank you (2 Replies)
Discussion started by: danbroz
2 Replies

8. Shell Programming and Scripting

Loop over multiple arrays

Hi All I need really really help with this :- I have two files ( File1 , File 2) both files are output of two different scripts. File1 usually has a list of names ( sometimes 3 names sometimes 5 sometimes more , depends about the output of the script) File2 usually has a list of numbers... (2 Replies)
Discussion started by: samsan
2 Replies

9. Shell Programming and Scripting

Multiple arrays in variable using for loop

Hi, I'm trying to get the number of files inside same kind of folders on each disks and assigning each values in to a variable named with same folder and disk name so that it'll be easy for me to identify each time.But somehow I'm not able to assign those values in that specific name variable... (1 Reply)
Discussion started by: ratheeshp
1 Replies

10. Programming

Looping an array of 2d arrays in C

Le sigh... Hopefully this will be the last time I have to ask for help on this topic. For a while now I've been working with a 1d array that holds 2d arrays. For reference you can view here. Now I'm just trying to loop through the elements with the following: #include <stdio.h> void... (3 Replies)
Discussion started by: Azrael
3 Replies
vbo_rendering(3)						       Coin							  vbo_rendering(3)

NAME
vbo_rendering - Vertex array and VBO rendering in Coin Coin 2.5 added improved support for OpenGL vertex array and VBO rendering. This might lead to major rendering performance improvements compared to the old rendering code. The new rendering code has been added for the SoIndexedFaceSet, SoVRMLIndexedFaceSet, SoIndexedLineSet, SoVRMLIndexedLineSet, SoPointSet and SoVRMLPointSet nodes. To take advantage of the improved performance vertex array and VBO rendering yields, you'll need to organize your vertex data in a way that makes it possible to render it with OpenGL vertex arrays. OpenGL vertex array rendering does not support multiple index arrays, so all your vertex data (coordinates, normals, colors and texture coordinates) must use the same index array; or use OVERALL binding. For the indexed nodes, this means that PER_VERTEX_INDEXED and OVERALL are the only supported bindings for materials, normals and texture coordinates. When PER_VERTEX_INDEXED binding is used, the corresponding index field should by empty. This will signal the shape to use the coordIndex field for indices. Below is an example scene graph that will be rendered using vertex arrays: NormalBinding { value PER_VERTEX_INDEXED } Coordinate3 { point [ 0 0 0, # 0 1 0 0, # 1 2 0 0, # 2 0 1 0, # 3 1 1 0, # 4 2 1 0, # 5 0 2 0, # 6 1 2 0, # 7 2 2 0, # 8 2 0 0, # 9 2 0 -1, # 10 2 1 0, # 11 2 1 -1, # 12 2 2 0, # 13 2 2 -1 # 14 ] } Normal { vector [ 0 0 1, # 0 0 0 1, # 1 0 0 1, # 2 0 0 1, # 3 0 0 1, # 4 0 0 1, # 5 0 0 1, # 6 0 0 1, # 7 0 0 1, # 8 1 0 0, # 9 1 0 0, # 10 1 0 0, # 11 1 0 0, # 12 1 0 0, # 13 1 0 0 # 14 ] } IndexedFaceSet { coordIndex [ 0, 1, 4, 3, -1, 1, 2, 5, 4, -1, 3, 4, 7, 6, -1, 4, 5, 8, 7, -1, 9, 10, 12, 11, -1, 11, 12, 14, 13, -1 ] normalIndex [ ] # = use coordIndex }.fi Please note that since only one index array can be used, it might be necessary to supply duplicate normals and coordinates to meet this requirement. Also, if normals are needed, you have to supply them. A shape with autogenerated normals can't be rendered using vertex arrays (since a single coordinate might get multiple normals). The PointSet nodes can always be rendered using vertex arrays since these nodes haven't got index arrays, and the only bindings supported are PER_VERTEX and OVERALL. If it's inconvenient to create vertex array ready scene graphs directly from your application, it's also possible to use SoReorganizeAction to reorganize the geometry before rendering. Version 3.1.3 Wed May 23 2012 vbo_rendering(3)
All times are GMT -4. The time now is 03:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy