I want to have a program that will ask questions.. and post top scores.. but these questions are randomly ask.. on the other hand.. these questions must be put in .textfile.. please help me.. im begging all of you..
my questions in txtfiles is this

1 What_is_the_capital_of_Europe? a.)Brussels b.)Brussiels c.)Berlin d.)Amsterdam e.)None_of_the_Above
2 Who_was_the_Inventor_of_Coca_Cola? a.)John_Pemberton b.)Ian_Wilmut c.)Thomas_Edison d.)Calvin_Johnson e.)Erik_Simon
3 What_is_the_capital_of_Germany? a.)Berlin b.)Brussels c.)Minsk d.)Bridgetown e.)Vienna
4 What_is_the_capital_of_china? a.)Bangkok b.)Bangcock c.)Bangcook d.)Bongkok e.)BengKok
5 What_muscle_makes_the_eye_move? a.)inferior_oblique_muscle b.)inferior_rectus_msucle c.)superior_rectus_msucle d.)superior_oblique_muscle_tendon e.)Sclera
6 What_is_the_alternate_name_of_x-coordinate? a.)abscissa b.)ordinate c.)booleane d.)string e.)none_of_the_above
7 Which_of_the_following_doesn't_belong_to_the_cat_family? a.)Airedale_Terrier b.)bobcat c.)Lion d.)Cougar e.)Lynx
8 It_is_called_the_"system_board"? a.)motherboard b.)chipboard c.)chipset d.)south_bridge e.)none_of_the_above
9 What_will_happen_if_you_plug_your_cpu_in_110V? a.)explode b.)nothing_happens c.)withdraw_lots_of_money d.)a_and_b e.)only_c
10 What_is_an_act_of_using_another_person's_ideas? a.)plagiarism b.)liberalization c.)Relegate d.)Hollistic e.)Ellipsis
11 What_is_the_other_name_for_"Three_spaced_periods"? a.)ellipsis b.)liberalization c.)Relegate d.)Hollistic e.)plagiarism
12 Who_was_the_first_president_of_United_States? a.)John_Hanson b.)Jan_Hanson c.)Jan_Handson e.)Jean_Hanson
13 Who_was_the_first_president_of_Iran? a.)Abolhassan_Bani-Sadr b.)Abolhasan_Bani-Sadr c.)Ali_Khamenei d.)b_only e.)c_only
14 How_many_minutes_in_an_hour? a.)60 b.)100 c.)90 d.)30 e.)45
15 Who_is_the_actor_the_film_"Sleepy_Hollow(1998)"? a.)Johnny_Depp b.)Christina_Ricci c.)Ichabod_Crane d.)Jet_Li e.)Jackie
16


temporarily..all the answers are letter a...

and my program was....

/*	Read a text file of integers, and print the contents.
	   Written by:
	   Date: 
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

int main (void)
{
//	Local Declarations 
	FILE* spIn;
	char numIn[100];
	char a;
	
//	Statements 
	spIn = fopen("Textfile.txt", "r");
	if (!spIn)
	   {
	    printf("Could not open file\a\n");
	    getch();
        exit  (101);
	   } // if open fail 
	
	while ((fscanf(spIn, "%s", &numIn)) == 1)
	   printf("%s \n", numIn);
	   printf("What is your answer?\n");
 scanf("%s",&a);
 
 if(a == 'a' || a == 'A')
{
 printf("\n\tYour answer is %c and it is Correct ",a);
 scanf("%s",&a);
}
 else
{
 printf("\n\tYour answer is %c and it is Wrong ",a);
 scanf("%s",&a);
	   
	getch();   
	return 0;
}
}	// main

please correct this program... please!! i need it badly

Recommended Answers

All 3 Replies

>>please correct this program... please!! i need it badly
So, what is wrong with it?

line 25 uses the wrong input function. fscanf("%s" ...) stops reading on the encounter of the first space. You should use fgets() instead to get the entire line

while( fgets( numIn, sizeof(numIn), spIn) )
{
    // strip the trailing '\n'
    if( numIn[strlen(numIn)-1] == '\n')
        numIn[strlen(numIn)-1] = = 0;
    // rest of code here
}

I'm also asking sir... about how to paste these questions in my txtfile in my output.. haha thanks man for helping

I guess you should first fix a nice format for question file
question:option1:option2...;answer or
something which you find suitable.

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.