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
You modify a document that is saved on your computer. Where are the changes stored until you save the document?a. Radom access m
BartSMP [9]

Answer:

a. Radom Access Memory (RAM).

Explanation:

If a computer user modifies a document that is saved on his or her computer. This changes are stored on the Radom Access Memory (RAM) until the computer user save the document.

Radom Access Memory (RAM) can be defined as the main memory of a computer system which allow users to store commands and data temporarily.

Generally, the Radom Access Memory (RAM) is a volatile memory and as such can only retain data temporarily.

All software applications temporarily stores and retrieves data from a Radom Access Memory (RAM) in computer, this is to ensure that informations are quickly accessible, therefore it supports read and write of files.

3 0
3 years ago
Which of the following is necessary to connect a computer outside of the hospital to the hospital's server?
dybincka [34]

Answer:

The answer is "Option C"

Explanation:

VPN reflects virtual private networking, providing secure networking and strong links between private networks. It helps us to use remote machines, that are like on the same local site, and we use VPN to reach the hospital website. And other choices which could be listed as follows that is not correct:

  • In option A, WAN represents a wide area network, it's used to connect computers through networking, that's why it's not correct.
  • In option B, LAN stands for local area network, it shares a common line or wireless links for communication, that's why it is not correct.
  • In option D, FOV stands for field of view that is used for gaming purposes, that's why it is not correct.
7 0
3 years ago
Modify the program you wrote for Chapter 6 Exercise 6 so it handles the following
Basile [38]

Answer:

#try except

try:

   #opening the file

   read_file = open('numbers.txt', 'r')

   #Store the numbers in the variable file_numbers.

   file_numbers = read_file.read()

   #close the file

   read_file.close()

   #Split the number of files in list_values.

   list_values = file_numbers.split()

   #how many numbers are there

   list_length = len(list_values)

   try:

       #loop it up

       for i in range(list_length):

           list_values[i] = float(list_values[i])

       #Add up all the numbers, put into list_sum

       List_sum = sum(list_values)

       #heres how we average it

       Average_value = (List_sum)/list_length

       #print

       print(Average_value)

   except ValueError:

       print( "File must have only numbers. Try again." )

   #handles IOError exceptions

except IOError:

   #Display statement

   print("Trouble opening file. Try again.")

Explanation:

The python program uses the try-except exception handling method to catch errors in the code. The IOError is used for catching input and output errors in the program like file handling while the ValueError keyword in the except statement is used to catch data type errors from a return statement, calculation or user input.

6 0
3 years ago
Which of the following statements about Java Class Libraries is false: a. Java class libraries consist of classes that consist o
blondinia [14]

Answer:

Statement D is false

D. Java class libraries are not portable = FALSE

Explanation:

Because java class library are portable and JVM (java virtual machine) makes java class library and other java codes portable and platform independent and JVM act as a OS or imaginary CPU for that code.

8 0
4 years ago
suppose you need to verify how to correctly use commas. you pen your English textbook and scan the chapter titles in which one w
Leviafan [203]
D- Proper punctuation
6 0
3 years ago
Other questions:
  • When creating a professional presentation, how many typefaces are recommended at the most?
    5·1 answer
  • You can create a database using one of the many templates available or by creating a new ______ database.
    9·1 answer
  • Indexed sequential access, an index is more useful when the number of record is
    10·1 answer
  • An organization uses SAP financial management software to store accounting details and Microsoft CRM software to record customer
    12·1 answer
  • URLs are directions that browsers follow in order to find specific web page files. What is the first part of the URL that is the
    14·1 answer
  • What is the name of the amount of space between the content of a document and the edge of the page
    13·1 answer
  • The Apple iPhone was a revolutionary product when it was introduced in 2007. To what extent do you agree or disagree with this s
    8·1 answer
  • A relational database is different from a simple database because it has more than one _____.
    13·1 answer
  • Compared to a virtual image, a real image
    15·2 answers
  • What legal protection would cover a person invention?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!