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 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top