Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to concatenate a string and int in C

2 Answers

0 votes
#include <stdio.h>

int main() {
    int i = 738;
    char s[32] = "c programming";
    char buf[64] = "";

    snprintf(buf, 64, "%s - %d", s, i);
    printf("%s\n", buf);

    return 0;
}




/*
run

programming - 738

*/

 



answered May 2, 2021 by avibootz
0 votes
#include <stdio.h>
#include <string.h>
 
int main() {
    char str[] = "Programming";
    int n = 31;
    char numStr[32]; 
    char result[64]; 
 
    // Convert integer to string
    sprintf(numStr, "%d", n);
 
    // Concatenate strings
    strcpy(result, str);
    strcat(result, numStr);
 
    printf("%s\n", result);
 
    return 0;
}
 
  
/*
run:
  
Programming31
   
*/

 



answered Jun 17, 2025 by avibootz

Related questions

2 answers 76 views
1 answer 144 views
144 views asked May 3, 2021 by avibootz
3 answers 70 views
2 answers 82 views
1 answer 104 views
1 answer 152 views
1 answer 142 views
...