I'm sorry if I violate any rule since I am new here, but I do have a question regarding some segmentation fault I receive while running the code I have been working on.
I am working on a card program and this is my input:
Code:
TS QC 8S 8D QH 2D 3H KH 9H 2H TH KS KC
9D JH 7H JD 2S QS TD 2C 4H 5H AD 4D 5D
6D 4S 9S 5S 7S JS 8H 3D 8C 3S 4C 6S 9C
AS 7C AH 6H KD JC 7D AC 5C TC QD 6C 3C
3C 6C QD TC 5C AC 7D JC KD 6H AH 7C AS
9C 6S 4C 3S 8C 3D 8H JS 7S 5S 9S 4S 6D
5D 4D AD 5H 4H 2C TD QS 2S JD 7H JH 9D
KC KS TH 2H 9H KH 3H 2D QH 8D 8S QC TS
What I am trying to do is read in 52 cards name into array, set up the game and play it, when the game is done, I read the next 52 cards and play it again.
However, I encounter segmentation fault while running the program. Here is my code
Code:
#include <stdio.h>#include <stdlib.h>
#include "header.h"
extern FILE *open_file();
//function prototype
void readData(FILE *input_file);
//main
main(int argc, char *argv[]){
FILE *input_file;
char file_name[32];
//command to run the lab and data: lab1 data
input_file = fopen(argv[1],"r");
readData(input_file);
fclose(input_file);
}
//other functions here
//read in the data
void readData(FILE *input_file){
char card_list[104];
FILE *current_fpt;
current_fpt = input_file;
//check if file error or not
if(input_file == NULL){
printf("Error opening input file");
}else{
do{
int i;
for(i=0;i<52;i++){
fscanf(current_fpt,"%s",&card_list[i]);
printf("%s\n",card_list[i]);
}
input_file = current_fpt;
}while(!feof(input_file));
}
}
I appreciate your help and please tell me where I did it wrong and if there are other ways to do this.