I'm very new to C, this is a test program that i'm trying to make work. The purpose is to put the characters from one dynamically generated matrix into another. The code i've got compiles but never finishes running.
When I comment out the loop at the bottom it will do the printf statement fine, but when I uncomment it it just keeps running and doesn't print. I though C worked sequentially? If something in the loop is broken why is it affecting the printf statement?
Here is the code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main (void)
{
int n,m,i;
char **matrix = (char**) malloc(m * sizeof(char*));
for ( i = 0; i < m; i++ )
{
matrix[i] = (char*) malloc(n * sizeof(char));
}
char **oldMatrix = (char**) malloc(m * sizeof(char*));
for ( i = 0; i < m; i++ )
{
oldMatrix[i] = (char*) malloc(n * sizeof(char));
}
n=1;
m=2;
int indc;
matrix[n][m];
matrix[1][1]='1';
matrix[1][2]='2';
oldMatrix[1][2];
printf("%c %c",matrix[1][1],matrix[1][2]);
int r=0;
for (indc=0; indc<=1; indc++)
{
printf("4");
oldMatrix[r][indc]=matrix[r][indc];
}
}