I do apologize for the lack of knowledge in this matter but it is very important for me, so at least I'll give it a try. I am using Visual Studio 2012 express on Windows 7 ultimate, I have written some very basic a silly program to practice structures in the C language. Unfortunately, one of the methods that I've written had a wrong condition to stop and it goes to an infinite loop and the worse part it exceeds the given array boundaries. I will add the code below BUT THE CODE IS NOT my main concern tho,I managed to fix it already, I only wish to know if I could harm my system or my personal files (videos, photos, office files etc.) with the given method because when I've tried to run this code, a scary thing happened, my pc started to "Beep" endlessly every 0.5 second and I could't do nothing to stop that, the program was on infinite loop and it I managed to stop this "fun" only with Ctrl + Alt + Del. I had written codes that crashed many times before, but I'ts sure the first time my pc strated to sound beeps. I hope an expert can help me out on this one. Many thanks.
The method with the infinite loop that cause all the problem is "printArrHero":
#include<stdio.h>
#include<string.h>
struct Date{
int day, month, year;
} typedef date_s;
struct Superhero{
char name[30];
double power, speed;
date_s birthday;
} typedef sp_s;
void printInfo(sp_s hero){
printf("Super hero info:\nName: [%s]\n" , hero.name);
printf("Power: [%.2lf]\n" , hero.power);
printf("Speed: [%.2lf]\n" , hero.speed);
printf("Birthday: [%d/%d/%d]\n\n" , hero.birthday.day, hero.birthday.month, hero.birthday.year );
}
void addHero (sp_s arr[], int *k, sp_s newHero){
arr[*k] = newHero;
(*k)++;
printf("\nSuccess! a new superhero is added.\n");
}
void printArrHero (sp_s arr[]){
int j=0;
while ( arr[j] != NULL ){
printf("[#%d]>>>>>>>>>>>>>>>>>>\n" , j+1);
printInfo( arr[j] );
j++;
}
}
void main(){
sp_s myHeros[100];
sp_s newHero;
int i = -1;
int k = 0;
while (i != 0){ // menu loop
printf("Welcome to my game!\n");
printf("To add a hero press 1\n");
printf("To find you're strongest hero press 2\n");
printf("To find you're fastest hero press 3\n");
printf("To see all of you're heroes list 4\n");
printf("To exit press 0\n");
scanf("%d" , &i);
switch (i){
case 0:
break;
case 1:
printf("Please enter the #%d hero characteristics:\nName: " , k+1);
scanf("%s" , &newHero.name);
printf("Power: ");
scanf("%lf" , &newHero.power);
printf("Speed: ");
scanf("%lf" , &newHero.speed);
printf("Birth date [xx/xx/xx](format): ");
scanf("%d/%d/%d" , &newHero.birthday.day, &newHero.birthday.month, &newHero.birthday.year);
addHero(myHeros, &k, newHero); // now when I collecten all the info needed to make a new hero lets send it to the func tht puts it in the #k place in the array
break;
case 2:
break;
case 3:
break;
case 4:
printArrHero(myHeros);
break;
} // END of switch-case
} // while menu loop
} // main