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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top