Like Tree3Likes
  • 2 Post By Elkvis
  • 1 Post By laserlight

error pls help

This is a discussion on error pls help within the C++ Programming forums, part of the General Programming Boards category; 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++) { ...

  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
    2,699
    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 10:46 AM. Reason: Corrected Typo, '\n' should have been '\0'

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    2,348
    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
    2,348
    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
    21,588
    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.
    Elysia likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 10:48 AM
  3. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  4. Replies: 1
    Last Post: 11-15-2010, 10:14 AM
  5. Replies: 3
    Last Post: 10-02-2007, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21