Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-2008, 05:47 PM
Irfanerol's Avatar   
Irfanerol Irfanerol is offline
Newbie
 
Join Date: May 2008
Posts: 11
Rep Power: 0
Irfanerol is on a distinguished road
Default A little problem with C

Hi my program isn't work well. There's a little problem. Maybe someone could help me? My gets(name) is not working. program always pass the gets line after executing it. I couldn't enter anything to name variable. And also this problem is only happening in a loop? What's the problem you think?


Here is the program

Code:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>


main()
{
	char name[30], sex;
	int n, counter, age;
	double gpa;

	FILE *inp, *outp;

	inp = fopen("stdlist.txt", "r");
	outp = fopen("stdlist.dat", "w");
	
	printf("How many students: ");
	scanf("%d", &counter);
	n=1;
	while(n<counter)
	{
		puts("Please enter student's name:");
	    gets(name);
		printf("Please enter student's sex (M or F): ");
		scanf("%c", &sex);
		printf("Please enter student's age: ");
		scanf("%d", &age);
		printf("Please enter student's GPA: ");
		scanf("%lf", &gpa);
		system("cls");


		printf("\n\n----------------------------------------\n\n");
		printf("This student's information is \nname: %s\nsex: %c\nage: %d\nGPA: %lf\n", name, sex, age, gpa);
		printf("\n------------------------------------------\n\n");


		printf("Please press a key for print these values to output file.\n");
		getch();
		fprintf(outp, "----------------------------------------------\nName:      %s\nSex:       %c\nAge:       %d\nGPA:       %0.2lf\n-----------------------------------------------\n\n", name, sex, age, gpa);
		n++;
	}
	return 0;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-05-2008, 06:07 PM
dcs dcs is offline
Programming Expert
 
Join Date: Mar 2008
Posts: 371
Rep Power: 6
dcs has a spectacular aura aboutdcs has a spectacular aura about
Default Re: A little problem with C

Question 12.18a
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-25-2008, 10:37 AM
mgoktwo mgoktwo is offline
Newbie
 
Join Date: Jul 2008
Posts: 2
Rep Power: 0
mgoktwo is on a distinguished road
Default Re: A little problem with C

i have changed somethings in your source code and i think it looks ok now...try this...

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>


main()
{
char name[30], sex[2];
int n, counter, age;
double gpa;

FILE *inp, *outp;

inp = fopen("stdlist.txt", "r");
outp = fopen("stdlist.dat", "w");

printf("How many students: ");
scanf("%d", &counter);
n=1;
do
{
printf("Please enter student's name:");
scanf("%s",name);
printf("Please enter student's sex (M or F): ");
scanf("%s", sex);
printf("Please enter student's age: ");
scanf("%d", &age);
printf("Please enter student's GPA: ");
scanf("%lf", &gpa);
system("cls");


printf("\n\n----------------------------------------\n\n");
printf("This student's information is \nname: %s\nsex: %c\nage: %d\nGPA: %lf\n", name, sex, age, gpa);
printf("\n------------------------------------------\n\n");


printf("Please press a key for print these values to output file.\n");
getch();
fprintf(outp, "----------------------------------------------\nName: %s\nSex: %c\nAge: %d\nGPA: %0.2lf\n-----------------------------------------------\n\n", name, sex, age, gpa);
n++;
}
while(n<counter);
return 0;
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-25-2008, 10:41 AM
mgoktwo mgoktwo is offline
Newbie
 
Join Date: Jul 2008
Posts: 2
Rep Power: 0
mgoktwo is on a distinguished road
Default Re: A little problem with C

Code:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>


main()
{
	char name[30], sex[2];
	int n, counter, age;
	double gpa;

	FILE *inp, *outp;

	inp = fopen("stdlist.txt", "r");
	outp = fopen("stdlist.dat", "w");
	
	printf("How many students: ");
	scanf("%d", &counter);
	n=1;
	do
	{
		printf("Please enter student's name:");
	    scanf("%s",name);
		printf("Please enter student's sex (M or F): ");
		scanf("%s", sex);
		printf("Please enter student's age: ");
		scanf("%d", &age);
		printf("Please enter student's GPA: ");
		scanf("%lf", &gpa);
		system("cls");


		printf("\n\n----------------------------------------\n\n");
		printf("This student's information is \nname: %s\nsex: %c\nage: %d\nGPA: %lf\n", name, sex, age, gpa);
		printf("\n------------------------------------------\n\n");


		printf("Please press a key for print these values to output file.\n");
		getch();
		fprintf(outp, "----------------------------------------------\nName:      %s\nSex:       %c\nAge:       %d\nGPA:       %0.2lf\n-----------------------------------------------\n\n", name, sex, age, gpa);
		n++;
	}
Code:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>


main()
{
	char name[30], sex[2];
	int n, counter, age;
	double gpa;

	FILE *inp, *outp;

	inp = fopen("stdlist.txt", "r");
	outp = fopen("stdlist.dat", "w");
	
	printf("How many students: ");
	scanf("%d", &counter);
	n=1;
	do
	{
		printf("Please enter student's name:");
	    scanf("%s",name);
		printf("Please enter student's sex (M or F): ");
		scanf("%s", sex);
		printf("Please enter student's age: ");
		scanf("%d", &age);
		printf("Please enter student's GPA: ");
		scanf("%lf", &gpa);
		system("cls");


		printf("\n\n----------------------------------------\n\n");
		printf("This student's information is \nname: %s\nsex: %c\nage: %d\nGPA: %lf\n", name, sex, age, gpa);
		printf("\n------------------------------------------\n\n");


		printf("Please press a key for print these values to output file.\n");
		getch();
		fprintf(outp, "----------------------------------------------\nName:      %s\nSex:       %c\nAge:       %d\nGPA:       %0.2lf\n-----------------------------------------------\n\n", name, sex, age, gpa);
		n++;
	}
	while(n<counter);
	return 0;
}
while(n<counter); return 0; }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-25-2008, 02:50 PM
dcs dcs is offline
Programming Expert
 
Join Date: Mar 2008
Posts: 371
Rep Power: 6
dcs has a spectacular aura aboutdcs has a spectacular aura about
Default Re: A little problem with C

User Input: Strings and Numbers [C]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Peculiar UI Problem Needs Tackling adriyel C# Programming 2 04-06-2008 08:46 AM
Problem read pwd protected Access2K dbase - CR9 & VB6 mrbar Visual Basic Programming 2 03-10-2008 05:50 AM
How to tackle a programming problem? TcM General Programming 10 01-07-2008 12:29 PM
i have a problem please help me!!!???? stack Java Help 8 09-22-2007 04:17 PM
[C] Comparison problem Alhazred C and C++ 1 08-29-2007 05:58 AM


All times are GMT -5. The time now is 11:42 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads