access violation error

Steven Schveighoffer schveiguy at yahoo.com
Wed Aug 13 14:35:42 PDT 2008


Most likely, this is failing because you are using scanf.  Stop using it :) 
Use din.readf instead:

import std.cstream;

char[] str;
din.readf("%s", &str);

-Steve

"Michael P." <baseball.mjp at gmail.com> wrote in message 
news:g7vi50$29f0$1 at digitalmars.com...
> /* junior304.d
> 2008 junior problem 3
> Smile with similies
> Ask for 2 numbers; the number of adjectives and nouns
> After you get the numbers and nouns and adjectives, out all possible 
> similies
> August 12th, 2008 */
>
> //Imports
> import std.stdio;
>
> /*****
> *Main*
> *****/
> void main()
> {
> int numberOfAdjectives;
> scanf( "%d", &numberOfAdjectives );
> int numberOfNouns;
> scanf( "%d", &numberOfNouns );
>
> char[][] adjectives; //array of strings to hold the adjectives
> adjectives.length = 6; //max number that user enters is 5, 6 to be safe
> char[][] nouns; //same as above, but for nouns
> nouns.length = 6; //same as adjectives reason
>
> //get adjectives first
> for ( int i = 0; i < numberOfAdjectives; i++ ) //get the specified # of 
> adjectives
> {
> scanf( "%s", &adjectives[ i ] );
> }
>
> //now get the # of nouns specified
> for ( int i = 0; i < numberOfNouns; i++ )
> {
> scanf( "%s", &nouns[ i ] );
> }
>
> //print out all possible similies
> for ( int i = 0; i < numberOfAdjectives; i++ )
> {
> for ( int j = 0; j < numberOfNouns; j++ )
> {
> //for every adjective, place a noun after and turn it into a similie
> writefln( "%s as %s", adjectives[ i ], nouns[ j ] );
> }
> }
> }
>
>
> I get an accessviolation when I enter the last 2 for loops; any reason 
> why?
>
> Input is:
> 3
> 2
> Easy
> Soft
> Smart
> pie
> rock
>
> error! 




More information about the Digitalmars-d-learn mailing list