Thread: I'm trying to master printf, but I'm having trouble concatenating values.

  1. #1
    Registered User
    Join Date
    Sep 2018
    Posts
    4

    I'm trying to master printf, but I'm having trouble concatenating values.

    Hi. I'm trying to concatenate 3 intergers, but I'm getting an error that says I'm missing a closing parentheses before a numeric constant. Here's the code:
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    //printf_Concatenation.c
    
    int main()
    {
        puts("Integers:");
        printf("As easy as %d, %d, and %d!"1,2,3);
        printf("The first number is %d, the second number is %d, and the third number is %d."1,2,3);
        
        puts("Strings:");
        printf("You are the %s link. Goodbye!\n","weakest");
        
        puts("Floating-Point Values and/or Fractions:");
        
        puts("Single Chars:");
        
        puts("Percentage");
        printf("I got %d%% on my C programming exam!\n",99);
    }
    The error for line 9 says:
    9 87 C:\Dev-C_Projects\printf_Concatenation.c [Error] expected ')' before numeric constant
    Last edited by UncleBazerko; 09-18-2018 at 11:29 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,730
    You forgot a comma, i.e., this:
    Code:
    printf("As easy as %d, %d, and %d!"1,2,3);
    should have been:
    Code:
    printf("As easy as %d, %d, and %d!", 1,2,3);
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting odd values from printf
    By Finoli in forum C Programming
    Replies: 15
    Last Post: 01-05-2016, 10:49 AM
  2. printing null values with printf
    By django in forum C Programming
    Replies: 12
    Last Post: 08-23-2011, 08:24 AM
  3. Printf Trouble
    By EvilGuru in forum C Programming
    Replies: 1
    Last Post: 11-11-2005, 02:06 PM
  4. printf returning values problem
    By hayai32 in forum C Programming
    Replies: 20
    Last Post: 06-25-2005, 12:16 PM
  5. trouble with printf alignment
    By hyaline in forum C Programming
    Replies: 5
    Last Post: 09-22-2001, 01:39 AM

Tags for this Thread