Thread: error pls help

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    3

    error pls help

    theres some syntax error in del functions definations pls help

    Code:
    void del(bank a[max],int size,int o)
    {
      for(int i=0;i<size;i++)
      {
        if(o==a[i].acc)
        {
          a[i].name=" ";
          a[i].fn= " ";
          a[i].add= " ";
          a[i].ph= " ";
          a[i].age=(char) " ";
          a[i].type=(char) " ";
          cout<<"\n Account is now deleted";
        }
        else
        cout<<"\n account doesn't exist";
      }
    }
    bold line shows error i want to replace prev. data by a space here
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,633
    You can't use the assignment operator to assign a C-string a value. But to "delete" the contents of a C-string you can change the first character of this string to the nul character ('\0'), and the int types can be set to zero.


    Jim
    Last edited by jimblumberg; 01-14-2013 at 11:46 AM. Reason: Corrected Typo, '\n' should have been '\0'

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    please do not attach files for code. paste your code in between code tags.

    in any case, on line 6 of your cpp file, you have a syntax error, declaring max without a type. also, in your various functions that take an array as a parameter, they are receiving a copy of the array, and modifying that copy. any changes made are lost when the function returns. you also don't check size anywhere to see if it's greater than max-1.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by jimblumberg View Post
    You can't use the assignment operator to assign a C-string a value. But to "delete" the contents of a C-string you can change the first character of this string to the nul character ('\n'), and the int types can be set to zero.

    Jim
    \n is not the nul character. \0 is.

  5. #5
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    Quote Originally Posted by jimblumberg View Post
    You can't use the assignment operator to assign a C-string a value. But to "delete" the contents of a C-string you can change the first character of this string to the nul character ('\0'), and the int types can be set to zero.


    Jim
    thnx jim

  6. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    Quote Originally Posted by Elkvis View Post
    please do not attach files for code. paste your code in between code tags.

    in any case, on line 6 of your cpp file, you have a syntax error, declaring max without a type. also, in your various functions that take an array as a parameter, they are receiving a copy of the array, and modifying that copy. any changes made are lost when the function returns. you also don't check size anywhere to see if it's greater than max-1.
    it doesn't matter with type of max coz its the size of array.
    checking size for max's value is is good idea i will add to it
    thnx

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Jatin Katyal
    it doesn't matter with type of max coz its the size of array.
    It is a syntax error to try and declare max without a type name.

    Besides this, you are using pre-standard headers, e.g., <iostream.h> should be <iostream>. void main should be int main.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 10-29-2012, 03:33 AM
  2. Replies: 15
    Last Post: 11-28-2011, 11:48 AM
  3. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  4. Replies: 1
    Last Post: 11-15-2010, 11:14 AM
  5. Replies: 3
    Last Post: 10-02-2007, 09:12 PM