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
AI Thread 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!
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top