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
Which of the following is Tynker an example of?
dangina [55]

Answer:

binary code

Explanation:

correct me if i’m wrong :)

6 0
3 years ago
Read 2 more answers
(Please help, Urgent Need): How do I change my username
stealth61 [152]

Answer: create a different one

Explanation:

6 0
3 years ago
1. Write a shell script, renumber.sh, that will rename all the files in a directory. The first argument is a base name, second a
Scilla [17]

Answer:

#!/bin/bash

if [ -z "$1" ] || [ -z "$2" ]

then

echo "invalid arguments"

exit 1

fi

filename="$1"

extension="$2"

cnt=1

for file in *. $extension

do

echo "renaming $file to $filename $cnt.$extension"

mv -i "$file" "$filename$cnt. $extension" #prompt before overwriting a file

cnt=$(( $cnt + 1 ))

done

Explanation:

6 0
4 years ago
Wireless internet is an example of telecommunications.
lawyer [7]
Anything is telecommunication if it has a <span>transmitter</span> and receiver. If you're a Host, then you're hosting (Transmitting) a connection. If you have a router as a customer or service, then you're receiving their signal (transmitting). You're the receiver. 
7 0
3 years ago
Bottom-up integration testing has as it's major advantage(s) that
irakobra [83]
It's C) no stubs need to be written
8 0
3 years ago
Other questions:
  • Which of the following does not describe local alignment algorithm?
    9·1 answer
  • When is e-mail an appropriate channel for goodwill messages? If you frequently communicate with the receiver by e-mail and are c
    15·1 answer
  • After you save a table, the new table name appears ____.
    12·2 answers
  • You are an IT technician at your company. The company has two small offices in different cities. The company's head office conta
    5·1 answer
  • What is the purpose of a Macro in Word?: *
    13·1 answer
  • Como se diseña y produce un material audiovisual
    5·1 answer
  • Moving your Sprite top to bottom is moving along the X coordinate?<br><br> True<br> False
    5·2 answers
  • Select the true statement about the motherboard.
    9·1 answer
  • Read the problem listed below. Formulate a Decomposition or Outline of the problem. Determine if you have seen this problem befo
    15·1 answer
  • Give the value of the zero flag, the carry flag, the signflag, and the overflow flag after each of the following instructions if
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!