- #1
doktorwho
- 181
- 6
Homework Statement
I am supposed to write a program in C that does the following:
It creates a 2d array from your specifications and as inputs takes only letters 'a' to 'z', 'A' to 'Z' and '*' and nothing else. It should immediately exit if something else is inputed. This array represents a crossword puzzle that the user creates and the '*' represent the blanks that separate words. The program should print and array in a matrix form (nxm) where n and m are inputted numbers of array length and find a row or a coloumn with biggest number of '*" appearances.
Homework Equations
3. The Attempt at a Solution [/B]
C:
#include "stdio.h"
#define MAX_I 500
#define MAX_J 500
int main(void) {
char words[MAX_I][MAX_J];
int n, m, i, j;
printf("Enter the length of your array: \n");
scanf("%d", &n);
printf("Enter the height of your array: \n");
scanf(" %d", &m);
printf("Enter the elements: \n");
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++) {
scanf("%c", &words[i][j]);
if (((words[i][j] >= 'a' && words[i][j] <= 'z') || (words[i][j] >= 'A' && words[i][j] <= 'Z')) || (words[i][j] == '*'))
{ //I am here checking if inputs are correct.
continue;
}
else {
printf("Invalid, program will exit now! \n");
goto finish;
}
}
}
finish:
return 0;
printf("\n");
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++) {
printf("%c", words[i][j]);
}
printf("\n"); //This is used so that it gets printed in matrix form.
}
}