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]
3 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]3 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
Corey wrote a code that will display his name every time he presses the down arrow key but there is a bug in it. Display letter
brilliants [131]

Answer:

Explanation:

display letter c, type letter r, type letter o, type letter 3, type letter y- i think thats it but i dee cay this is confusing

7 0
3 years ago
Corona and app inventor can be used to develop ________.
Sidana [21]
<span>Corona and app inventor can be used to develop apps for smartphones. Corona can be used to build both games and apps from major platforms like iOS, Android, Kindle, Apple TV, Android TV, macOS, and Windows. App Inventor was originally provided by Google and is now maintained by MIT.</span>
3 0
4 years ago
In a school 50% of the students are younger than 10, 1/20 are 10 years old and 1/10 are older than 10 but younger than 12, the r
Zielflug [23.3K]

Answer: 10 students

Explanation:

Students younger than 10 = 50%

Students that are 10years old = 1/20 = 1/20 × 100 = 5%

Students that are older than 10 but younger than 12 = 1/10= 1/10 × 100 = 10%

Students that are 12 years or older

= 100% - (50% + 5% + 10%)

= 100% - 65%

= 35%

This means that 35% of the students are 12 years or older and we've been given the number as 70.

Let's say the total number of students is x. Therefore,

35% of x = 70

0.35 × x = 70

0.35x = 70

x = 70/0.35

x = 200

The total number of students is 200.

Therefore, the number of students that are 10years will be:

= 1/20 × 200

= 10 students

Therefore, 10 students are 10 years.

3 0
3 years ago
To increase usability, take care to place important content, such as logos, names, CTAs, and major links, ______ of potential sc
tangare [24]

Answer:

b. above and to the left

Explanation:

To increase usability, take care to place important content, such as logos, names, CTAs, and major links, above and to the left of potential scroll lines.

6 0
3 years ago
Write a 5 sentence paragraph about why charles babbage invented the computer.
Colt1911 [192]

Answer:

The computer was invented in order to automate mathematical calculations that were previously completed by people. Charles Babbage is considered to be the “father” of the computer.

Explanation:

4 0
2 years ago
Read 2 more answers
Other questions:
  • Urgent help<br> Write a program that prints ‘Hello World’ to the screen
    8·1 answer
  • The process of encoding messages or information in such a way that only authorized parties can read it is called ____________.
    7·1 answer
  • Each processor core on a multi core processor generally runs faster than a single core processor
    14·2 answers
  • Windows workstations all have elements of server software built-in. What are these elements, and why is the Windows Professional
    9·1 answer
  • How is the bootstrap program started?
    6·2 answers
  • Look at the network topology. What will happen with the other computers if the computer breaks at the RED X?
    8·1 answer
  • 1. Name the first PC virus.<br> 2. In which language are viruses written for Microsoft programs?
    8·2 answers
  • ________ use statistics to anticipate customers withdrawals. ________ use statistic to calculate probable life expectancy to hel
    11·1 answer
  • Consider the method get Hours, which is intended to calculate the number of hours that a vehicle takes to travel between two mil
    6·1 answer
  • 2 what is deep learning?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!