Thread: string prefixes in C programming

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    1

    Unhappy string prefixes in C programming

    I am writing code to let a user enter two strings
    string1
    string2

    I want the program to tell me if the two strings match and if they have a matching prefix and a matching suffix and then prompt the user with the "yes it did match " and these are the matching prefixes and suffixes. Can anybody help me? this is the code i have so far///please email me or im me to tell me whats up Thanks, Spooky


    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<math.h>
    int main(void)
    {

    int number;
    int sum;
    int i;
    int option;
    char string1[80];
    char string2[80];

    printf("\nWelcome to Project 5!!!");
    printf("\nPlease type 1 for strings or 2 for pythagorean triples: ");
    scanf("%d", &option);
    if(option==1){
    printf("\nYou have chosen the program for strings");
    printf("\nPlease enter string 1 <ctrl d to quit>: \n1: ");
    scanf("%s", string1);
    printf("\nPlease enter string 2 <ctrl d to quit>: \n2: ");
    scanf("%s", string2);
    }
    if(strcmp(string1,string2)==0)
    printf("You have a match!!!");
    else
    printf("You do not have a match"

    if(strstr(string1, string2)==NULL)
    printf("\n\"%s\" was not found.", string2);
    else
    printf("\n\"%s\" was found in \"%s\"", string2, string1);




    return 0;
    }

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    10
    your code works now you need to put {} <---those when using if else statements!

    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<math.h>
    
    int main(void)
    {
    
      int number;
      int sum;
      int i;
      int option;
      char string1[80];
      char string2[80];
    
      clrscr(); /*clears the screen*/
    
     printf("\nWelcome to Project 5!!!");
     printf("\nPlease type 1 for strings or 2 for pythagorean triples: ");
     scanf("%d", &option);
     if(option==1){
     printf("\nYou have chosen the program for strings");
     printf("\nPlease enter string 1 <ctrl d to quit>: \n1: ");
     scanf("%s", string1);
     printf("\nPlease enter string 2 <ctrl d to quit>: \n2: ");
     scanf("%s", string2);
    }
    
     if(strcmp(string1,string2)==0){
         printf("You have a match!!!");
    }
      else{
              printf("You do not have a match");
    }
    
    if(strstr(string1, string2)==NULL){
        printf("\n\"%s\" was not found.", string2);
    }
      else
             printf("\n\"%s\" was found in \"%s\"", string2, string1);
    
    getch();
    return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ ini file reader problems
    By guitarist809 in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2008, 06:02 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM