3 Replies - 442 Views - Last Post: 19 November 2012 - 03:15 PM Rate Topic: -----

#1 taqihusain  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 15
  • Joined: 15-November 12

how to assign a null value to a string

Posted 19 November 2012 - 11:18 AM

how to assign a null value to a string please tell me
Is This A Good Question/Topic? 0
  • +

Replies To: how to assign a null value to a string

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: how to assign a null value to a string

Posted 19 November 2012 - 11:40 AM

You need to show some code that shows what you have tried. Is this a C++ string or a C string?

Jim
Was This Post Helpful? 0
  • +
  • -

#3 aresh  Icon User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,176
  • Joined: 08-January 12

Re: how to assign a null value to a string

Posted 19 November 2012 - 11:41 AM

What does null value mean? The string should be empty? Also, which string? std::string or C-string?
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1112
  • View blog
  • Posts: 4,619
  • Joined: 09-June 09

Re: how to assign a null value to a string

Posted 19 November 2012 - 03:15 PM

Null is usually used to simply terminate a string. Otherwise the standard string library functions have no idea where the end of the string ends.

i.e.
char arr[6] {'a', 'b', 'c', 'd', 'e', 'f'}; //no null terminator
printf("%s", arr); //printf will print all memory until a 0 is found in memory, very dangerous

arr[5] = '\0'; //replace 'f' with null terminator

printf("%s", arr); //prints abcde


This post has been edited by jjl: 19 November 2012 - 03:15 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1