LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-20-2011, 11:27 AM   #1
SithArrow
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
Not printing out anything


I have this whole speal of scripting supposed to print out a series of information and all it ends up printing is what day it is.
The script:
Code:
# include  <stdio.h>
# include  <math.h>
# include  <string.h>


	// defines the max size and max number of passes
#define MAX_SIZE 30
#define MAX_PASSES 5


	// the structs that are given in the assignment 
typedef struct
{
	int hour;
	int minute;
	char ampm[3];
} time_type;

typedef struct
{
	char ride_name[MAX_SIZE];
	time_type ride_time;
} fastpass_type;

typedef struct
{
	char first_name[MAX_SIZE];
	char last_name[MAX_SIZE];
	fastpass_type passes[MAX_PASSES];
	int num_passes;
} customer_type;  


	//prototype
int checkName (customer_type tmpP,customer_type person);
int checkRide (customer_type tmpP, customer_type person);
int checkTime (fastpass_type tmpPass, customer_type person);


int main()
{    
    customer_type person [500]; 
    customer_type tmpP ; 
	
	
    int i,j,k;
	int n, maxP, amtP=0;
	int newP, tmpPass;
	int time;
	
    FILE *ifp = fopen ("fastpass.txt", "r"); 
    fscanf ( ifp, "%d" , &n);
    
		// first for loop to read in the number of days
    for (i = 0; i < n; i++)
    {
		
        printf("UCF FAST PASSES DAY %d\n", i+1);
		fscanf (ifp, "%d",  &maxP);
		
		
			// reads in the number of people for the day
		for(j = 0; j < maxP; j++)
		{
			
			fscanf (ifp, "%s%s%s%d%d%s",  
					tmpP.first_name,
					tmpP.last_name, 
					tmpP.passes[0].ride_name,  
					&tmpP.passes[0].ride_time.hour,
					&tmpP.passes[0].ride_time.minute,
					tmpP.passes[0].ride_time.ampm );
			
			
				//compares the names                  
			for (k = 0; k < amtP; k++)
			{
				
				newP = checkName (tmpP, person[k]);
				
					// the return 0 mean the person is new
				if ( newP == 0)
				{
					break;
				}
			}
			
			if (k == amtP)
			{
				amtP++;
				strcpy( person[k].first_name, tmpP.first_name); 
				strcpy( person[k].last_name, tmpP.last_name); 
				strcpy( person[k].passes[0].ride_name, tmpP.passes[0].ride_name);
				strcpy( person[k].passes[0].ride_time.ampm, tmpP.passes[0].ride_time.ampm);
				person[k].passes[0].ride_time.hour = tmpP.passes[0].ride_time.hour;
				person[k].passes[0].ride_time.minute = tmpP.passes[0].ride_time.minute;
				person[k].num_passes = 1;
			}
			
			else if (person[k].num_passes == MAX_PASSES)
			{
				printf("%s%s: Pass denied for ride %s at %d %2d%s.\n", tmpP.first_name, tmpP.last_name, tmpP.passes[i].ride_name, 
					   &tmpP.passes[i].ride_time.hour, &tmpP.passes[i].ride_time.minute, tmpP.passes[i].ride_time.ampm);
			}
			
			else 
			{
				tmpPass = checkRide (tmpP, person[k]);
				
				if (tmpPass == 0 )
				{ 
					printf("%s%s: Pass denied for ride %s at %d %2d%s.\n", tmpP.first_name, tmpP.last_name, tmpP.passes[i].ride_name, 
						   &tmpP.passes[i].ride_time.hour, &tmpP.passes[i].ride_time.minute, tmpP.passes[i].ride_time.ampm);
				}
				
				else
				{
                    printf("%s%s: Pass granted for ride %s at %d %2d%s.\n", tmpP.first_name, tmpP.last_name, tmpP.passes[i].ride_name, 
						   &tmpP.passes[i].ride_time.hour, &tmpP.passes[i].ride_time.minute, tmpP.passes[i].ride_time.ampm);
				}
				
				time = checkTime (tmpP.passes[0], person[k]);
				
				if (time == 0 )
				{
                    printf("%s%s: Pass denied for ride %s at %d %2d%s.\n", tmpP.first_name, tmpP.last_name, tmpP.passes[i].ride_name, 
						   &tmpP.passes[i].ride_time.hour, &tmpP.passes[i].ride_time.minute, tmpP.passes[i].ride_time.ampm);              
				}
				
				else
				{
					printf("%s%s: Pass granted for ride %s at %d %2d%s.\n", tmpP.first_name, tmpP.last_name, tmpP.passes[i].ride_name, 
						   &tmpP.passes[i].ride_time.hour, &tmpP.passes[i].ride_time.minute, tmpP.passes[i].ride_time.ampm);
				}
			}
		}
	}
	return 0;   
    
}






	//checks the names of the customer
int checkName (customer_type tmpP,customer_type person)
{
	int i,j,k,l;
	int char_diff;
				char first_cus[30],first_temp[30],last_cus[30],last_temp[30];
				int fNameLen = strlen(tmpP.first_name);
				int lNameLen = strlen(tmpP.last_name);
				
					// takes the name and makes it upper case
				for(i = 0; i < strlen(tmpP.first_name); i++)
					first_temp[i] = toupper(tmpP.first_name[i]);
				for(j = 0; j < strlen(person.first_name); j++)
					first_cus [j]= toupper (person.first_name[j]);
				for(k = 0; k < strlen(tmpP.first_name); k++)
					last_temp[k] = toupper (tmpP.last_name[k]);
				for(l = 0; l < strlen(tmpP.first_name); l++)    
					last_cus[l] = toupper (person.last_name[l]);
				
				if(fNameLen != strlen(person.first_name) || lNameLen != strlen(person.last_name))
					return 1;
				
				
				if(strcmp(first_cus, first_temp) == 0)
				{
					if(strcmp(last_cus,  last_temp) == 0)
						return 0;
					else 
					{
						for (i=0; i < lNameLen ; i++)
						{
							if(tmpP.last_name[i] == '\0')
							{
								if(person.last_name[lNameLen - i] == '\0')
									return 0;
								else
									return 1;
							}
							if(tmpP.last_name[i] != person.last_name[lNameLen - i])
								char_diff++;
							
							if(char_diff > 1)
								return 1;
						}
					}
					
				}
				else
				{
					for (i=0; i < fNameLen ; i++)
					{
						if(tmpP.first_name[i] == '\0')
						{
							if(person.first_name[fNameLen - i] == '\0')
								return 0;
							else
								return 1;
						}    
						if(tmpP.first_name[i] != person.first_name[fNameLen - i])
							char_diff++;
						
						if(char_diff > 1)
							return 1;
					}
				}
}
				 
				 
int checkRide (customer_type tmpP, customer_type person)
{
					//compares of the cutomer already used a fast pass fo a ride
				if (strcmp(tmpP.passes[0].ride_name, person.passes[0].ride_name) == 0)
					return 0;
				else
					return 1;
			}
int checkTime (fastpass_type tmpPass, customer_type person)
			{
				int mil, min, mil_t, min_t,i;
					// converts hours to miltary time then to minuets and adds the two values for the cutomer that already has fast passes
				for ( i =0 ; i < person.num_passes; i++)
				{
					if (strcmp(person.passes[0].ride_time.ampm, "PM") ==0)
					{
						mil = person.passes[0].ride_time.hour +12;
						min = (mil * 60) + person.passes[0].ride_time.minute; 
						
					}
					else
					{
						mil_t = person.passes[0].ride_time.hour;
						min_t = (mil * 60) + person.passes[0].ride_time.minute; 
					}
						//converts hours to miltary time then to minuets and adds the two values for the cutomer that wants a new fast pass
					if ( strcmp(tmpPass.ride_time.ampm, "PM") ==0)
					{
						mil_t = person.passes[0].ride_time.hour +12;
						min_t = (mil * 60) + person.passes[0].ride_time.minute; 
					}
					
					else
					{
						mil_t = person.passes[0].ride_time.hour;
						min_t = (mil * 60) + person.passes[0].ride_time.minute; 
					}
						// hopfully subtrac the two vales will gives the the time from the last fast pass
					if (( abs (min-min_t)) < 60) 
					{
						return 1;
					}
					else
					{
						return 0;
					}
					
				}
}
The input file is

Quote:
Sample Input File (fastpass.txt)
2
11
Bill Johnson RollerCoasterOfLove 11 0 AM
Will Johnson CrazyTeaCups 11 55 AM
Llib JoHnSoN Movie3D 12 0 PM
Bill Johnson HeartLand 3 0 PM
Ellen Walker RollerCoasterOfLove 11 0 AM
Bill Johnson Rave 1 1 PM
Bill Johnson CartoonHour 2 0 PM
Bill Johnson RollerCoasterOfLove 4 0 PM
Bill Johnson WhalesAreUs 5 25 PM
Bill NOSNHOJ Fireworks 8 30 PM
Ellen Walker Rave 3 25 PM
1
Rob Bradshaw Movie3D 2 13 PM
And I should wind up with:

Quote:
Sample Output
UCF FAST PASSES DAY 1
Bill Johnson: Pass granted for ride RollerCoasterOfLove at 11:00 AM.
Bill Johnson: Pass denied for ride CrazyTeaCups at 11:55 AM.
Bill Johnson: Pass granted for ride Movie3D at 12:00 PM.
Bill Johnson: Pass granted for ride HeartLand at 3:00 PM.
Ellen Walker: Pass granted for ride RollerCoasterOfLove at 11:00 AM.
Bill Johnson: Pass granted for ride Rave at 1:01 PM.
Bill Johnson: Pass denied for ride CartoonHour at 2:00 PM.
Bill Johnson: Pass denied for ride RollerCoasterOfLove at 4:00 PM.
Bill Johnson: Pass granted for ride WhalesAreUs at 5:25 PM.
Bill Johnson: Pass denied for ride Fireworks at 8:30 PM.
Ellen Walker: Pass granted for ride Rave at 3:25 PM.

UCF FAST PASSES DAY 2
Rob Bradshaw: Pass granted for ride Movie3D at 2:13 PM.
But it only prints the UCF FAST PASSES DAY 1 and 2
 
Old 04-20-2011, 12:37 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
The best way to approach this problem is to step through your code under the debugger.

Here's a good link:
http://heather.cs.ucdavis.edu/~matlo...age/Debug.html

For example, if you used gdb to set a breakpoint here:
Code:
       printf("UCF FAST PASSES DAY %d\n", i+1);
		fscanf (ifp, "%d",  &maxP);
		
			// reads in the number of people for the day
		for(j = 0; j < maxP; j++)
... and then printed out our value for "maxP"
... then you might be surprised
 
Old 04-20-2011, 01:28 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Quote:
Originally Posted by SithArrow View Post
I have this whole speal of scripting
That's not scripting.

http://www.google.com/search?client=...UTF-8&oe=UTF-8
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
banner printing - printing across multiple pages - in Linux, any suggestions? pbhj Linux - Software 3 11-07-2008 09:22 AM
[Printing] Confidential Printing with Sharp AR-M350 kabalak Linux - Hardware 5 10-01-2008 07:14 AM
Printing with CUPS to hplaserjets only printing 1 line zmag2linux Linux - Newbie 1 02-01-2008 10:48 AM
Whats the difference between CUPS printing and Samba shared printing? depam Linux - Software 1 03-17-2006 01:56 PM
Scribus Printing How to put 4 flyers on a page when printing jazzboy Linux - Software 0 05-02-2004 06:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration