C/C++ Problems with C program- Not C++ and not Java

  • Thread starter Thread starter jasonsmith206
  • Start date Start date
  • Tags Tags
    C++ Java Program
Click For Summary
The discussion revolves around a programming task where a user inputs a word and a number, which need to be read into specified variables and then printed in a specific format. The solution involves using the `scanf` function to capture the input and the `printf` function to format the output as "word_number". A user expresses frustration over a previous attempt that didn't yield the correct output, mistakenly assigning variables instead of formatting them correctly. The response highlights the importance of understanding pointers and arrays in C programming, providing a clear solution to the problem. The interaction emphasizes the collaborative nature of the forum, with users seeking and offering help on coding challenges.
jasonsmith206
Messages
10
Reaction score
0
A user types a word and a number on a single line. Read them into the provided variables. Then print: word_number. End with newline. Example output if user entered: Amy 5

Amy_5
#include <stdio.h>int main(void) {
char userWord[20] = "";
int userNum = 0;

/* Your solution goes here */

return 0;
}Was part of homework but its over a week old. Just want to know how to work it and any help would be greatly appreciated.

Thanks!
 
Technology news on Phys.org
Hi, and welcome to the forum.

One way to finish the program is
Code:
  scanf("%s %d", userWord, &userNum);
  printf("%s_%d\n", userWord, userNum);

To understand it, you need to know about pointers and their relation to arrays.
 
wow!

i did everything right on scanf but instead of printing what you've got i put (userWord and userNum to = word_number).. so close yet so far. Thank you so much for your help that one was driving me crazy!
 
Anthropic announced that an inflection point has been reached where the LLM tools are good enough to help or hinder cybersecurity folks. In the most recent case in September 2025, state hackers used Claude in Agentic mode to break into 30+ high-profile companies, of which 17 or so were actually breached before Anthropic shut it down. They mentioned that Clause hallucinated and told the hackers it was more successful than it was...

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
10K
  • · Replies 0 ·
Replies
0
Views
492
  • · Replies 2 ·
Replies
2
Views
13K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 25 ·
Replies
25
Views
2K
Replies
14
Views
3K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
6K
Replies
89
Views
6K