473,395 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

when we use pointers in predefined string functions why is gives runntime error.the c

Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. void main()
  3. {
  4.     char *a="your";
  5.     char *b="name";
  6.     printf("%s",strcpy(a,b));
  7. }
Aug 17 '13 #1
1 1140
weaknessforcats
9,208 Expert Mod 8TB
You are copying string b to string a.

Unfortunately, string a is a literal which means the string is const. The compiler will not let you change the value of a literal.

Change the program to use arrays:

Expand|Select|Wrap|Line Numbers
  1. char a[] ="your";
  2. char b[] ="name";
  3. etc...
BTW: strcpy assumes the destination array is big enough to hold the source string. It's up to you to be sure this is true.
Aug 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John F Dutcher | last post by:
There must be a 'fundamental' reason why 'string' functions are reported as 'not found' even though the 'import string' statement is present. If the script has user-defined functions at its...
2
by: Thomas Matthews | last post by:
Hi, I would like to create a table (or vector) of pointers to templated functions. 1. How do I declare a typedef of a pointer to a templated function? For example, I have some functions...
4
by: lovecreatesbeauty | last post by:
How many member functions will be predefined (provided by compilers implicitly) and called by standard-compliant compilers for a class? Does such a list be given in iso/iec 14882? Which member...
11
by: Gregory L. Hansen | last post by:
I'm playing with a simulation where different parts of a system, like a controller or a thermometer or a thermal mass, are represented as classes, instantiated, and connected together like...
4
by: Ian Malone | last post by:
I have a class which looks like this: class reco { public: int height, width; double beta; double mu; simple_d_field estimate; simple_d_field auxiliary;
4
by: Protoman | last post by:
Why doesn't this code work; it should: class Obj { public: void a(){cout << "A!" << endl;} void b(){cout << "B!" << endl;} void c(){cout << "C!" << endl;} };
6
by: massic80 | last post by:
Hi, it's me again! I have a strange problem with a form I gotta (dynamically) insert in a site, and copied/pasted the code to a blank page, to make it easier to try it out. I was using the $...
3
by: googlinggoogler | last post by:
Hi This should all be pretty standard C stuff, but I'm going to use terms like mouse callback to communicate what Im tyring to do. Basically I have my program whirling around in an infinite...
1
by: questionit | last post by:
I am getting error on all string Functions i.e Left, Mid, etc Error is that i haven't set the library... I am getting this error when i downloaded a Access file from internet and compiled...
3
by: Ramesh | last post by:
Hi, I am trying to create an array of pointers to member functions inside my class. When I created a global array of type pfn & initialized with member functions and copy it back to the member...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.