Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Corrections/Correction_C.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main()
// FIXME: Array
// create a new string array called "shoppingList", with three elements of your choice. Create an int variable containing the number of
// elements in "shoppingList" (using a function of the array/using the array)
char *shoppingList[3] = {"milk", "a Chevy Camaro", "a life"};
char *shoppingList[3] = {"milk", "a Chevy Camaro", "a life", NULL};
const int nbOfElements = numberOfElements(shoppingList);

// FIXME: For-loop - Integer
Expand All @@ -67,8 +67,14 @@ int main()

// FIXME: For-loop - shoppingList
// Create a for loop that iterate through "shoppingList" and prints each element with "You have to buy (elemt)".
for (int j = 0; j <nbOfElements; j++)
printf("You have to buy %s\n", shoppingList[j]);
{
for (char **p=shoppingList; p && *p; p++)
{
int cur_index=p-shoppingList;
char *cur_element=*p;
printf("You have to buy %s\n", cur_element);
}
}


// FIXME: Foreach-loop
Expand Down
5 changes: 3 additions & 2 deletions Corrections/Correction_Ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@

# FIXME: For-loop - shoppingList
# Create a for loop that iterate through "shoppingList" and prints each element.
for i in 0..nb_of_elts - 1
puts shoppingList[i];
shoppingList.each do
|element|
puts element
end

# FIXME: Foreach-loop
Expand Down