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
The spoken version of your company's purpose is called
beks73 [17]

Answer:

The answer to this question is given below in the explanation section. The correct answer is A

Explanation:

The spoken version of the company's purpose is also called an elevator pitch. because it has to be short enough to fit into a conversation that takes place on an elevator.

however the other options are not correct that tells the purpose of a company, because the vision statement shows what you will be at what stage in next coming year (in terms of growth, product /services etc). Your values are about what uniqueness you have in your product/service etc that you are providing to your customers/clients. While differentiation is not a spoken version of your company.

7 0
4 years ago
To process the elements in an array, the counter in a for loop is commonly used as the ________________ of the array. -g
kobusy [5.1K]
Index




----------------------------------
8 0
3 years ago
What is cell address?​
Nat2105 [25]

Answer:

A cell reference, or cell address, is an alphanumeric value used to identify a specific cell in a spreadsheet. Each cell address contains “one or more letters” followed by a number. The letter or letters identify the column and the number represents the row.

Explanation:

3 0
3 years ago
What is the difference between autofocus and autocomplete
Vladimir [108]

Answer:

https://www.c-sharpcorner.com/interview-question/explain-autofocus-and-autocomplete-attribute

found this on a website hope you find it useful !

8 0
3 years ago
True of False - use T or F An abstract class can have instances created using the constructor of the class.
Sindrei [870]

Answer:

False

Explanation:

An instance of an abstract class cannot be created through the constructor of the class, because it does not have a complete implementation. Though, it is possible to have references of an abstract type class. Abstract classes are incomplete structures and you would have to build onto it before you are able to use it.

7 0
4 years ago
Other questions:
  • I want to know all the part of computer system
    14·1 answer
  • Dr. Laos gets a referral for a 6 month old who has become listless and stopped eating lately. Her pediatrician wanted her to be
    15·1 answer
  • Write a program using integers user_num and x as input, and output user_num divided by x three times. Ex: If the input is: 2000
    15·1 answer
  • An internal _____ refers to a specific representation of an internal model, using the database constructs supported by the chose
    8·1 answer
  • What is the best way to improve the following code fragment? if ((counter % 10) == 0) { System.out.println("Counter is divisible
    13·1 answer
  • Which ieee 802.11 standard provides for throughput of up to 7 gbps?
    8·1 answer
  • Which of the following statements is used to terminate the program when closing the frame?
    12·1 answer
  • You wish to use a file system that creates a record or log of to-be-committed changes in the system so that if the system crashe
    14·1 answer
  • write a function named list_total that accepts a list as an argument (assume the list contains integers) and returns the cumulat
    11·1 answer
  • Which of these is NOT a benefit of being connected 24/7?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!