Thread: Help for letter count generating program

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    7

    Help for letter count generating program

    Design a program with the following specifications:
    Prompt the user for an alphabet.
    Continue to prompt until a valid alphabet has been entered.
    Starting with the user inputted alphabet, print every alphabet up to and including ‘z’ or ‘Z’
    For example:
    User enters ‘Q’: QRSTUVWXYZ
    User enters ‘s’: stuvwxyz

    so far I have, any help would be appreciated.
    Code:
    #include <stdio.h>
    
    
    #define CHARACTER 26 // max size of array
    
    char printstring (char str[]);//prototype
    
    int main(void)
    
    	{  
    	  char i[CHARACTER]; 
    	  printf("Please enter a capital or lowercase letter:");
    	  printstring (i);
         printf("%c",i);
    
    	  return (0);
    	}
    
    char printstring (char str[]);
    	{
    	return str;
    		scanf("%c", str);
    	  for(i='a';i<='z';i++){printf("%s",i);}
    	  for(i='A';i<='Z';i++){printf("%s",i);}
    	  getch();
    	}
            //if(string[i]>='a' && string[i]<='z') word++;
            //if(string[i]>='A' && string[i]<='Z') word++;

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    char printstring (char str[]);
    	{
    	return str;
    That first colored ; basically turns what you're trying to have as a function, into a prototype. You want to remove that.
    Code:
    char printstring (char str[])
    	{
    	return str;
    And THAT line would make your function immediately end, rendering everything else in the function useless.
    Code:
      for(i='a';i<='z';i++){printf("%s",i);}
    %s prints a string, you probably want %c, to print a single character.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    45
    i understand the problem, but your code is not solving it. its just printing out letters

    you need to incorporate the letter the user gives you into the for loop so that you only print out part of the alphabet.

    your also trying to print i which is in the main function. you either need to change what you are printing or declare i again in this new context

  4. #4
    Registered User
    Join Date
    Jun 2010
    Posts
    7

    thanks

    thanks for the help guys.

    Can anybody paste up a solution though?

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No. This forum isn't here so people can do your work for you. It's here so you can post what you are stuck on, we can point out this and that, you correct your code and try again.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    7
    I got the solution, i realized that i didnt even need arrays, thanks guys

    Code:
    #include <stdio.h>
    
    int main (void)
    	{
    	char i;
    	int rc;
    	do{
    	fflush (stdin);//flushes the input value on each loop
    	printf("Please enter a lower case or capital letter.Only the first digit will be considered):");
    	rc=scanf("%c", &i);
    	if (i>='a' && i<='z') rc=1; //condition for loop
    	else if (i>='A' && i<='Z') rc=1; //condition for loop
    	else rc=0;// condition for loop
    
    		}	while(rc!=1);
    
    	if (i>='a' && i<='z') for (i=i;i<='z';i++) printf("%c", i);
    	else for (i=i;i<='Z';i++) printf("%c", i);
    
    	getch();
    	}

  7. #7
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You should visit the FAQ and read why fflush( stdin ) isn't guaranteed to work like you want it to. I'm not sure why you're capturing the return value of scanf if you don't actually do anything with it other than immediately overwrite it. You should turn on compiler warnings, which will let you know that you're reaching the end of a non-void function (main) without returning anything.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Free program I'm sharing: ConvertEnumToStrings
    By Programmer_P in forum Projects and Job Recruitment
    Replies: 101
    Last Post: 07-18-2010, 12:55 AM
  2. Replies: 2
    Last Post: 05-02-2010, 01:49 AM
  3. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM