Im a beginner programmer and i was struggling to understand why this solution doesn't work. When i run the program it prints nothing
So the exercise goes like this:
We are supposed to enter an array of numbers(but i was lazy to keep entering them again and again so i wrote a sequence in a file) and what we are supposed to do is we have to find the largest sequence of non-zero numbers and print every sequence that is as big as that one. Meaning for example if we have
1 1 1 0 2 3 0 0 1 0 2 4 5
We would only print
1 1 1
and
2 4 5
for now i am just trying to print the array without zeros or where there are zeroes i would like to print a new line but i dont get why its not working. If possible can you give me an idea on how to do it?
This is my program so far:
#include <stdio.h>
#include <stdlib.h>
#define N 100
int main()
{
int v[N];
int i=0;
int j;
int n=0;
FILE *file;
file=fopen("file","r");
if(file==NULL)
{
printf("Error in the file.....");
exit(1);
}
while(fscanf(file,"%d",&v[n])!=EOF)
{
n++;
}
printf("Original Matrix: ");
for(i=0;i<n;i++)
{
printf("%d ",v[i]);
}
printf("\n\n\n");
while(i<n)
{
if(v[i]==0)
{
i++; \\i assume that the problem lies here but i dont understand why. Im just
trying to tell it that if its a 0 you should skip it. Maybe im doing it
wrong but i dont see how yet
}
else
{
printf("%d",v[i]);
}
i++;
}
return 0;
}