Character Game - C Programming -


i need code. question is:

write function void printsquare(char c, int size) accepts letter of alphabet , number between 3 , 10 , generates following rectangle of letters:

if letter passed a , size 4:

abcd bcde cdef defg 

if letter w , size 6, output should be

wxyzab xyzabc yzabcd zabcde abcdef bcdefg 

i have been trying debug long time , cannot anywhere , need help. code looks right now:

void printsquare(char c, int size); int main() {      printsquare('b', 4);      system("pause");     return 0; }   void printsquare(char c, int size){     int counter = 0;     char letters[26] = { 'a', 'b', 'c', 'd',         'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',         'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };     (int = 0; < 26; i++){         if (c == letters[i]){             int temp = i;             (int j = 0; j < size; j++){                 letters[i] = letters[temp];                 temp++;                 (int k = 0; k < size; k++){                     printf("%c", letters[i]);                     letters[i++];                 }                 printf("\n");             }         }     } } 

assuming encoding capital , small letters sequential (e.g. ascii), may consider this:

void printsquare(char c, int size) {     char = ('a' <= c && c <= 'z') ? 'a' : 'a';     (int = 0; < size; ++i)     {         (int j = 0; j < size; ++j)             // (c - a) offset of c 'a' or 'a'             // defines offset every line, lines start c, c+1, ...             // j defines offset character within line             // % 26 makes sure overall offset not go beyond alphabet length             printf("%c", + (c - + + j) % 26);         printf("\n");     } } 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -