1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dybincka [34]
4 years ago
14

I have a real struggle when it comes to working with strings, whether they're arrays or pointers to strings, and I'm lost cause

when I read or watch tutos I understand them, but then I'm like a novice when I need to write actual code, what should I do?
PS: I'm using C language.
Computers and Technology
1 answer:
neonofarm [45]4 years ago
6 0
In C, you deal with a string always via a pointer. The pointer by itself will not allocate memory for you, so you'll have to take care of that.

When you write char* s = "Hello world"; s will point to a "Hello world" buffer compiled into your code, called a string literal.

If you want to make a copy of that string, you'll have to provide a buffer, either through a char array or a malloc'ed bit of memory:

char myCopy[100];
strcpy(myCopy, s);

or 

char *myCopy;
myCopy = (char*)malloc( strlen(s) + 1 );
strcpy(myCopy, s);

The malloc'ed memory will have to be returned to the runtime at some point, otherwise you have a memory leak. The char array will live on the stack, and will be automatically discarded.

Not sure what else to write here to help you...
You might be interested in
Your traffic light changes to yellow as you approach an intersection. In most cases, what action should you take?
mamaluj [8]
Make every reasonable effort to stop.
6 0
4 years ago
Read 2 more answers
Which key should you press to change the cell contents to your typed data
Free_Kalibri [48]

You can edit the contents of a cell directly in the cell. You can also edit the contents of a cell by typing in the formula bar.

When you edit the contents of a cell, Excel is operating in Edit mode. Some Excel features work differently or are unavailable in Edit mode.

4 0
3 years ago
Read 2 more answers
Copyright laws protect:This task contains the radio buttons and checkboxes for options. The shortcut keys to perform this task a
agasfer [191]

B- Copyright laws protect original works both online and in print.

3 0
3 years ago
When you add an rss feed to hootsuite publisher, posts from blogs and websites you designate will be?
Cloud [144]

All answers are correct.

Source and explanation: certificationanswers.com/en/category/hootsuite-platform/

8 0
3 years ago
Question # 12
PIT_PIT [208]
It is ordinances hope this helps
8 0
3 years ago
Other questions:
  • You have just installed the microsoft windows 7 operating system on your pc. which web browser is bundled with windows 7 and is
    12·1 answer
  • Does an android tablet have a hard drive
    7·1 answer
  • Write a program that reads the contents of the two files into two separate lists. The user should be able to enter a boy’s name,
    6·1 answer
  • What are expansion cards used for?​
    9·2 answers
  • In this problem, you will write three methods to:
    12·1 answer
  • What file name would allow you to easily find and edit your document later in Word Online?
    14·2 answers
  • Tell me the errors please
    14·1 answer
  • Which measurement symbol is this?<br>PLS HELP<br>​
    14·1 answer
  • What does this map key show
    12·1 answer
  • Pls help me, it's due today​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!