cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
copy one string to another string up to
copy one string to another string up to some no of characters
Mar 31, 2010 at 5:36am UTC
yakubpasha
(8)
char* category;//i'll pass some string using function
for( i=0;i<noOfRecords;i++){
char string[30];
char* mystring;
size_t len=strlen(category);
strcpy(mystring,category,len-1);
sprintf(string,"%s",labValueRecords->category);
labValueRecords++;
if(strcmp(string,mystring)==0){
count++;
}
}
when i run this it giving an error like
The variable 'mystring' is being used without being initialized.
plz help me
thanks
regards yakub
Mar 31, 2010 at 5:42am UTC
firedraco
(6247)
mystring is a pointer to random memory, which may or may not be writable, so when you use strcpy() and try to copy to it, you could be writing to invalid memory.
Mar 31, 2010 at 6:52am UTC
yakubpasha
(8)
thank you dude ...
Topic archived. No new replies allowed.