Inputting to Char Arrays from Keyboard - Linux/GCC

  • Thread starter Thread starter rambo3131
  • Start date Start date
  • Tags Tags
    Arrays Keyboard
Click For Summary

Discussion Overview

The discussion revolves around how to input strings into two separate character arrays in C using the Linux environment and GCC compiler. Participants explore methods for capturing input from the keyboard, particularly focusing on how to differentiate between inputs for the first and second arrays based on the use of the Enter key.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant asks how to input characters into two char arrays, with the first array capturing input before pressing Enter and the second array capturing input after pressing Enter.
  • Another participant expresses confusion about the initial request, seeking clarification on the intended input process.
  • A participant suggests using functions like scanf or gets for input, questioning the original poster's familiarity with input methods in C.
  • One participant interprets the request as needing to copy strings from one array to another, proposing the use of strccpy() or memcpy() for this purpose.
  • The original poster clarifies that they do not mean to copy strings but rather want to input two separate lines into two different arrays.
  • Another participant questions the original poster's knowledge of pointers, suggesting that understanding pointers may be beneficial for solving the problem.
  • The original poster acknowledges their limited knowledge of pointers and expresses a willingness to study further before asking for more help.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the best approach to the problem. There are differing interpretations of the original request, and multiple suggestions for input methods have been proposed without agreement on a single solution.

Contextual Notes

There is uncertainty regarding the specific requirements for input handling, including the need for clarity on how to manage input across multiple lines and the role of pointers in the proposed solutions.

Who May Find This Useful

Individuals learning C programming, particularly those interested in handling character arrays and keyboard input in a Linux environment.

rambo3131
Messages
18
Reaction score
0
Hi,I have a question about C.I have declared two char arrays.I want to write one string through one line to take them first array.When ı touch enter and go to next line ,it will place my charecters which have been given later touching enter to second array.What can I do this? ,please help me .(.By the way I use linux and gcc compiler and ı must take inputs from keyboard not from file).
 
Technology news on Phys.org
rambo3131 said:
Hi,I have a question about C.I have declared two char arrays.I want to write one string through one line to take them first array.When ı touch enter and go to next line ,it will place my charecters which have been given later touching enter to second array.What can I do this? ,please help me .(.By the way I use linux and gcc compiler and ı must take inputs from keyboard not from file).

It's not clear what you're asking.
"I want to write one string through one line to take them first array." - What does this mean?

"When ı touch enter and go to next line ,it will place my charecters which have been given later touching enter to second array." - What does this mean?
 
ı mean : before ı clicked enter, i will write some charecters from keyboard .These must be taken first char array.Then, i will click enter then go to next line.Later i will write some charecters again,but this time these must be taken second char array .
 
You can use scanf or gets for input. Do you know how to do input in C?
 
I think he means he wants to copy the string from one array to the other before asking for another line of inputs. You can use strccpy() if these are zero terminated strings, or memcpy() if you know the lenghts of the strings.
 
No ,ı don't mean copy.while taking input ı will write this:


abcdefg klmnfgftrgfdgdgdg dsdghbvd hhyjdsv mjkkdsdg dsrghjmd
bsxatujkolhfdsrfb fgg edfgshdh sdgsgdh gfsdgsg sgsgs ıluıuıl jyujtjdjyj


first line must be taken array 1,second line must be taken array 2.
 
OK, so what have you tried?
 
rambo3131 said:
No ,ı don't mean copy.while taking input ı will write this:


abcdefg klmnfgftrgfdgdgdg dsdghbvd hhyjdsv mjkkdsdg dsrghjmd
bsxatujkolhfdsrfb fgg edfgshdh sdgsgdh gfsdgsg sgsgs ıluıuıl jyujtjdjyj


first line must be taken array 1,second line must be taken array 2.

How much knowledge do you have about pointers?
 
My sense is that rambo3131 is waiting for someone to come along and write his program for him.
 
  • #10
I don't know pointers well .Do you really think that i must know pointers to solve this problem?
 
  • #11
A little knowledge of pointers would be helpful.

As I said in post #4, you can use scanf or gets for input. Do you know how to do input in C?
 
  • #12
yes ,i will study for a while myself .If i have a problem,i ll ask .thank you
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 65 ·
3
Replies
65
Views
7K
  • · Replies 25 ·
Replies
25
Views
4K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
2
Views
2K
  • Poll Poll
  • · Replies 4 ·
Replies
4
Views
1K
Replies
3
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K