PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

[FIXED] How do i "delete" useless , after scanf()

 October 30, 2022     c, eof, scanf     No comments   

Issue

Here is a piece of my code : And output looks like: 12, 44, 55, I need to remove the last one ", " and i tried everything.

while ((r = scanf("%d", &v)) > 0){
        printf("%d", v);
        printf(", ");
        }

Solution

Instead of printing the comma after each value, print it before each value except the first:

int first = 1;
while ((r = scanf("%d", &v)) > 0){
    if (!first) printf(", ");
    first = 0;
    printf("%d", v);
}


Answered By - dbush
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing