Inputting to Char Arrays from Keyboard - Linux/GCC

  • Thread starter Thread starter rambo3131
  • Start date Start date
  • Tags Tags
    Arrays Keyboard
AI Thread Summary
The discussion revolves around a user seeking help with C programming, specifically on how to manage input from the keyboard into two separate char arrays. The user wants to input a string in one line, press enter, and then input another string on the next line, with the first line being stored in the first array and the second line in the second array. Suggestions include using functions like scanf or gets for input. There is also a mention of using string manipulation functions such as strcpy or memcpy, but the user clarifies that they are not looking to copy strings but rather to separate input into two arrays based on line breaks. The conversation touches on the importance of understanding pointers in C, although the user admits to limited knowledge in that area and expresses a willingness to learn further.
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

Back
Top