hi can someone give this a quick look over and tell me where im going wrong

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

void main()
{
	struct Rainfall{
		char city[20];
		int month;
		int rainfall;
	};

	Rainfall Rainfallarray[18];
	
	int count=0;

	FILE * readfile;
	readfile=fopen("CityRain.txt","r");
	if(readfile==NULL)
	{
		printf("CityRain.txt failed to open.");
		exit(1);
	}

	printf("CityRain.txt Opened\n");

	while(!feof(readfile))
	{
		fscanf(readfile, "%[^,],%d,%d%*c",Rainfallarray[count].city,Rainfallarray[count].month,Rainfallarray[count].rainfall);
		count++;
		printf("In loop%d",count);
	}





	fclose(readfile);

	system("pause"); //OMG MORE RANDOM COMMENTS
}

im getting

Unhandled exception at 0x6fdde30e (msvcr100d.dll) in Assingment.exe: 0xC0000005: Access violation writing location 0xcccccccc.

Recommended Answers

All 2 Replies

Investigate how the *scanf family of functions work. You must provide an address of a variable, not the variable itself.

ah fk how did i miss that, qqqqqqq ty

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.