Access Violation!!

This is a discussion on Access Violation!! within the C++ Programming forums, part of the General Programming Boards category; Code: char** Delete(char** Names){ // <---- here? cout << "Name: "; cin >> temp1; for (int x=0; x<=count; x++){ if ...

  1. #1
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    857

    Access Violation!!

    Code:
    char** Delete(char** Names){ // <---- here?
    	cout << "Name: ";
       cin >> temp1;
       for (int x=0; x<=count; x++){
       	if (strcmp(Names[count], temp1)){ // <<----- I think it is here...
          	cout << "Deleted\n";
             return (Names);
          }
          if (x==count){
          	cout << "Not found!!\n";
             return 0;
          }
       }
    
    }
    Thank you.

    I tried everything... from 2-d arrays to pointers... Ac Vi always.
    Yoshi

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    almost certainly you are overstepping the bounds of your array in the loop. try < instead of <= and see what happens. hard to tell from snippet but thats my educated guess.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,802
    Should probably be Names[x] and not Names[count] perhaps.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    857
    Nope, still doesn't work

    Code:
    #include<iostream.h>
    #include<stdio.h>
    #include<string.h>
    
    int count = 0;
    char*  temp1;
    
    
    char** Add(char** Names){
       count++;
       Names = new char*[count];
    	cout << "Name: ";
       cin >> Names[count];
       return (Names);
    }
    
    
    char** Delete(char** Names){
    	cout << "Name: ";
       cin >> temp1;
       for (int x=0; x<count; x++){
       	if (strcmp(Names[x], temp1)){
          	cout << "Deleted\n";
             return (Names);
          }
          if (x-1==count){
          	cout << "Not found!!\n";
             return 0;
          }
       }
    
    }
    
    
    void Find(char** Names){
    	cout << "Name: ";
       cin >> temp1;
       for (int x=0; x<count; x++){
       	if (strcmp(Names[x], temp1)){
          	cout << "Found at Location " << count;
             return;
          }
          if (x-1==count){
          	cout << "Not found!!\n";
             return;
          }
       }
    
    }
    
    
    int main(){
       char choice;
       char* Names[1];
       do{
       	cout << "Choose action (Add/Delete/Find/Quit): ";
       	cin >> choice;
       	if (choice == 'A' || choice == 'a')
    	   	Add(Names);
       	else if (choice == 'D' || choice == 'd')
       		Delete(Names);
       	else if (choice == 'F' || choice == 'f')
       		Find(Names);
       	else{
          	return 0;
       	}
    	}while(choice !='q' || choice != 'Q');
       delete Names;
       return 0;
    
    }
    the full code.
    Yoshi

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>char* Names[1];
    An array of 1 ? Seems a bit strange to me.

    >>Add(Names);
    The Add() function returns something, but you aren't assigning it to anywhere.

    There's a few others too, but I don't have time right now to show you them.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Access violation... can't figure it out...
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2007, 10:52 AM
  2. access violation in int array
    By George2 in forum C Programming
    Replies: 2
    Last Post: 08-02-2007, 11:28 PM
  3. FtpFileFind access violation with MS VC++ 6.0
    By earth_angel in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2005, 07:02 PM
  4. Help! CListCtrl access violation
    By bonkey in forum Windows Programming
    Replies: 4
    Last Post: 11-18-2003, 01:40 PM
  5. 0xC0000005: Access Violation
    By Strider in forum Windows Programming
    Replies: 3
    Last Post: 11-07-2001, 01:46 PM

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