|
Write a program that reads a number and a symbol from a file (diamondData.txt) and prints a diamond constructed from the given symbol, with that many symbols at the center. It should repeat this until the number 0 is read. If an even number is read it should read the symbol next to it, but print a message. For example if the line of data is
6 *
it should print
Can't process. Invalid data: 6 *
and go on to the next line of data. Sample input file:
5 M 11 * 6 H 7 # 0
Sample output:
M MMM MMMMM MMM M
* *** ***** ******* ********* *********** ********* ******* ***** *** *
Can't process. Invalid data: 6 H
# ### ##### ####### ##### ### #
Hint: for each row
* count and print some spaces, then * count and print some characters.
Here is my code, I have no clue what I'm doing
#include<stdio.h> #define sentinel 0
int main(void) { /*Declaring variables for file streams*/
FILE* Data_in; int number; /*number that represent the number of symbols you will use*/ char symbol;/*the type of symbol next to the the number*/ int i;/*counting the items*/ int center_symbols;/*number of symbols in the middle*/
/*open the files*/
Data_in =fopen("diamondData.txt","r"); /*input file*/
/*read first piece of data*/ fscanf(Data_in, "%d %c", &number, &symbol);
/*initialize variables*/ i = symbol; center_sumbols = 0; restriction = number%2; number = 1;
while(center_symbols <= number) { printf(" %c ",i); printf(" %c%c%c ",i,i,i);
}
|