Solved

strinfs

Posted on 1997-02-19
1
229 Views
Last Modified: 2012-05-04
How do I work strings like in BASIC?
IE How do string's work in C?
0
Comment
Question by:Robert Mcnulty
1 Comment
 
LVL 2

Accepted Solution

by:
morleys earned 50 total points
ID: 1249382
Strings don't realy exist in c (although forms of them exist is c++). In base c you work with char pointers which point to a section of allocated memory. A string array is terminated, by convention, with a null character. Thus the c string "abc" is stored in four bytes of which the last is zero. You would declare this as, for example,  char sampleStr[4]="abc";
To copy that string to another you might try:
  char newString[20];
  strcpy(newString, sampleStr);
Then you could tack on another string as
  strcat(newString, "this is more");
which would search for the null in newString and start copying the bytes. But it is the programmers job to make sure that the array is not overwritten which is a VERY bad thing. This is not easy stuff, but is part of the heart of the c language which allows you to get a pointer to something and do with it what you would, like cast it to something else.

I recomemd that you try c++ and use one of the string classes provided which can do much more by dynamically allocating space and warning of overruns.

Good Luck.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question