Displaying asterisks vs. displaying characters with a function










-1















I wrote a function (asterisksDisplay) that displays a solid rectangle of asterisks whose sides are specified in the integer parameters as row and column, which are taken from the user. The program below works perfectly.



#include <stdio.h>

void asterisksDisplay (int row, int column);

int main (void)

int a=0;
int b=0;
printf("Please enter sides of your shape: ");
scanf("%d%d", &a, &b);
printf("nYour shape is: n");
asterisksDisplay(a, b);


void asterisksDisplay (int row, int column)

for (int i = 1; i <= row; i++)
for (int p = 1; p <= column; p++)
printf("*");

printf("n");




When I try to modify this function of asterisks to a function of a user given character display, somehow compiler skips displaying the character.



#include <stdio.h>

void asterisksDisplay (int row, int column, char character);
int main (void)

int a=0;
int b=0;
char c;
printf("Please enter sides of your shape: ");
scanf("%d%d", &a, &b);
printf("nplease enter the character to be filled: ");
scanf("%s", &c);
printf("n");
asterisksDisplay(a, b, c);


void asterisksDisplay (int row, int column, char character)

for (int i = 1; i <= row; i++)
for (int p = 1; p <= column; p++)
printf("%c", character);

printf("n");




what is the solution for fixing this?










share|improve this question




























    -1















    I wrote a function (asterisksDisplay) that displays a solid rectangle of asterisks whose sides are specified in the integer parameters as row and column, which are taken from the user. The program below works perfectly.



    #include <stdio.h>

    void asterisksDisplay (int row, int column);

    int main (void)

    int a=0;
    int b=0;
    printf("Please enter sides of your shape: ");
    scanf("%d%d", &a, &b);
    printf("nYour shape is: n");
    asterisksDisplay(a, b);


    void asterisksDisplay (int row, int column)

    for (int i = 1; i <= row; i++)
    for (int p = 1; p <= column; p++)
    printf("*");

    printf("n");




    When I try to modify this function of asterisks to a function of a user given character display, somehow compiler skips displaying the character.



    #include <stdio.h>

    void asterisksDisplay (int row, int column, char character);
    int main (void)

    int a=0;
    int b=0;
    char c;
    printf("Please enter sides of your shape: ");
    scanf("%d%d", &a, &b);
    printf("nplease enter the character to be filled: ");
    scanf("%s", &c);
    printf("n");
    asterisksDisplay(a, b, c);


    void asterisksDisplay (int row, int column, char character)

    for (int i = 1; i <= row; i++)
    for (int p = 1; p <= column; p++)
    printf("%c", character);

    printf("n");




    what is the solution for fixing this?










    share|improve this question


























      -1












      -1








      -1








      I wrote a function (asterisksDisplay) that displays a solid rectangle of asterisks whose sides are specified in the integer parameters as row and column, which are taken from the user. The program below works perfectly.



      #include <stdio.h>

      void asterisksDisplay (int row, int column);

      int main (void)

      int a=0;
      int b=0;
      printf("Please enter sides of your shape: ");
      scanf("%d%d", &a, &b);
      printf("nYour shape is: n");
      asterisksDisplay(a, b);


      void asterisksDisplay (int row, int column)

      for (int i = 1; i <= row; i++)
      for (int p = 1; p <= column; p++)
      printf("*");

      printf("n");




      When I try to modify this function of asterisks to a function of a user given character display, somehow compiler skips displaying the character.



      #include <stdio.h>

      void asterisksDisplay (int row, int column, char character);
      int main (void)

      int a=0;
      int b=0;
      char c;
      printf("Please enter sides of your shape: ");
      scanf("%d%d", &a, &b);
      printf("nplease enter the character to be filled: ");
      scanf("%s", &c);
      printf("n");
      asterisksDisplay(a, b, c);


      void asterisksDisplay (int row, int column, char character)

      for (int i = 1; i <= row; i++)
      for (int p = 1; p <= column; p++)
      printf("%c", character);

      printf("n");




      what is the solution for fixing this?










      share|improve this question
















      I wrote a function (asterisksDisplay) that displays a solid rectangle of asterisks whose sides are specified in the integer parameters as row and column, which are taken from the user. The program below works perfectly.



      #include <stdio.h>

      void asterisksDisplay (int row, int column);

      int main (void)

      int a=0;
      int b=0;
      printf("Please enter sides of your shape: ");
      scanf("%d%d", &a, &b);
      printf("nYour shape is: n");
      asterisksDisplay(a, b);


      void asterisksDisplay (int row, int column)

      for (int i = 1; i <= row; i++)
      for (int p = 1; p <= column; p++)
      printf("*");

      printf("n");




      When I try to modify this function of asterisks to a function of a user given character display, somehow compiler skips displaying the character.



      #include <stdio.h>

      void asterisksDisplay (int row, int column, char character);
      int main (void)

      int a=0;
      int b=0;
      char c;
      printf("Please enter sides of your shape: ");
      scanf("%d%d", &a, &b);
      printf("nplease enter the character to be filled: ");
      scanf("%s", &c);
      printf("n");
      asterisksDisplay(a, b, c);


      void asterisksDisplay (int row, int column, char character)

      for (int i = 1; i <= row; i++)
      for (int p = 1; p <= column; p++)
      printf("%c", character);

      printf("n");




      what is the solution for fixing this?







      c scanf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 14:26









      Sourav Ghosh

      109k14129188




      109k14129188










      asked Nov 13 '18 at 14:15









      BelverusBelverus

      22027




      22027






















          1 Answer
          1






          active

          oldest

          votes


















          1














          Change



           scanf("%s", &c);


          to



           scanf(" %c", &c);
          ^^-----------------------(i)
          ^^------------------------- (ii)


          • Change of the conversion specifier from %s to %c, as (i): because c is a char type.


          • We need to escape the previously entered newline, so the extra whitespace before the conversion specifier, which matches and discards any leading whitespace input present in the buffer.






          share|improve this answer























          • I've tried it but unfortunately, this is not the solution. Also, Xcode insists that I should change the %c to %s on scanf. I will try the code on visual studio and post the result.

            – Belverus
            Nov 13 '18 at 17:27











          • @Belverus any updates?

            – Sourav Ghosh
            Nov 14 '18 at 4:40











          • I tried the code with Visual Studio. If I change the %s with %c as you suggested, It still skips the output. Program gets 2 integers as size of our shape, and displays "Please enter character" and exits the program. If I keep %s it gives an error: Not enough arguments passed for format string.

            – Belverus
            Nov 15 '18 at 8:20











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282985%2fdisplaying-asterisks-vs-displaying-characters-with-a-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Change



           scanf("%s", &c);


          to



           scanf(" %c", &c);
          ^^-----------------------(i)
          ^^------------------------- (ii)


          • Change of the conversion specifier from %s to %c, as (i): because c is a char type.


          • We need to escape the previously entered newline, so the extra whitespace before the conversion specifier, which matches and discards any leading whitespace input present in the buffer.






          share|improve this answer























          • I've tried it but unfortunately, this is not the solution. Also, Xcode insists that I should change the %c to %s on scanf. I will try the code on visual studio and post the result.

            – Belverus
            Nov 13 '18 at 17:27











          • @Belverus any updates?

            – Sourav Ghosh
            Nov 14 '18 at 4:40











          • I tried the code with Visual Studio. If I change the %s with %c as you suggested, It still skips the output. Program gets 2 integers as size of our shape, and displays "Please enter character" and exits the program. If I keep %s it gives an error: Not enough arguments passed for format string.

            – Belverus
            Nov 15 '18 at 8:20
















          1














          Change



           scanf("%s", &c);


          to



           scanf(" %c", &c);
          ^^-----------------------(i)
          ^^------------------------- (ii)


          • Change of the conversion specifier from %s to %c, as (i): because c is a char type.


          • We need to escape the previously entered newline, so the extra whitespace before the conversion specifier, which matches and discards any leading whitespace input present in the buffer.






          share|improve this answer























          • I've tried it but unfortunately, this is not the solution. Also, Xcode insists that I should change the %c to %s on scanf. I will try the code on visual studio and post the result.

            – Belverus
            Nov 13 '18 at 17:27











          • @Belverus any updates?

            – Sourav Ghosh
            Nov 14 '18 at 4:40











          • I tried the code with Visual Studio. If I change the %s with %c as you suggested, It still skips the output. Program gets 2 integers as size of our shape, and displays "Please enter character" and exits the program. If I keep %s it gives an error: Not enough arguments passed for format string.

            – Belverus
            Nov 15 '18 at 8:20














          1












          1








          1







          Change



           scanf("%s", &c);


          to



           scanf(" %c", &c);
          ^^-----------------------(i)
          ^^------------------------- (ii)


          • Change of the conversion specifier from %s to %c, as (i): because c is a char type.


          • We need to escape the previously entered newline, so the extra whitespace before the conversion specifier, which matches and discards any leading whitespace input present in the buffer.






          share|improve this answer













          Change



           scanf("%s", &c);


          to



           scanf(" %c", &c);
          ^^-----------------------(i)
          ^^------------------------- (ii)


          • Change of the conversion specifier from %s to %c, as (i): because c is a char type.


          • We need to escape the previously entered newline, so the extra whitespace before the conversion specifier, which matches and discards any leading whitespace input present in the buffer.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 14:17









          Sourav GhoshSourav Ghosh

          109k14129188




          109k14129188












          • I've tried it but unfortunately, this is not the solution. Also, Xcode insists that I should change the %c to %s on scanf. I will try the code on visual studio and post the result.

            – Belverus
            Nov 13 '18 at 17:27











          • @Belverus any updates?

            – Sourav Ghosh
            Nov 14 '18 at 4:40











          • I tried the code with Visual Studio. If I change the %s with %c as you suggested, It still skips the output. Program gets 2 integers as size of our shape, and displays "Please enter character" and exits the program. If I keep %s it gives an error: Not enough arguments passed for format string.

            – Belverus
            Nov 15 '18 at 8:20


















          • I've tried it but unfortunately, this is not the solution. Also, Xcode insists that I should change the %c to %s on scanf. I will try the code on visual studio and post the result.

            – Belverus
            Nov 13 '18 at 17:27











          • @Belverus any updates?

            – Sourav Ghosh
            Nov 14 '18 at 4:40











          • I tried the code with Visual Studio. If I change the %s with %c as you suggested, It still skips the output. Program gets 2 integers as size of our shape, and displays "Please enter character" and exits the program. If I keep %s it gives an error: Not enough arguments passed for format string.

            – Belverus
            Nov 15 '18 at 8:20

















          I've tried it but unfortunately, this is not the solution. Also, Xcode insists that I should change the %c to %s on scanf. I will try the code on visual studio and post the result.

          – Belverus
          Nov 13 '18 at 17:27





          I've tried it but unfortunately, this is not the solution. Also, Xcode insists that I should change the %c to %s on scanf. I will try the code on visual studio and post the result.

          – Belverus
          Nov 13 '18 at 17:27













          @Belverus any updates?

          – Sourav Ghosh
          Nov 14 '18 at 4:40





          @Belverus any updates?

          – Sourav Ghosh
          Nov 14 '18 at 4:40













          I tried the code with Visual Studio. If I change the %s with %c as you suggested, It still skips the output. Program gets 2 integers as size of our shape, and displays "Please enter character" and exits the program. If I keep %s it gives an error: Not enough arguments passed for format string.

          – Belverus
          Nov 15 '18 at 8:20






          I tried the code with Visual Studio. If I change the %s with %c as you suggested, It still skips the output. Program gets 2 integers as size of our shape, and displays "Please enter character" and exits the program. If I keep %s it gives an error: Not enough arguments passed for format string.

          – Belverus
          Nov 15 '18 at 8:20


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53282985%2fdisplaying-asterisks-vs-displaying-characters-with-a-function%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Barbados

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3