int main( )
{
	char theWord[ MAXWORD ];
	FILE *wordBank;
	int n = 0;
    
	wordBank = fopen( "guesswords.txt", "r" );

    if( wordBank == NULL )
    {
        printf( "Could not open input file...\n" );
        return -1;
    }

	fscanf( wordBank, "%s", &theWord[ n ] );

	lower_string( &theWord );

	play( &theWord );

	fclose( wordBank );

	return 0;
}
Exemplo n.º 2
0
std::wstring ParseFile(std::wstring& str)
{
	std::string LowerWorkingDir = lower_string(WStringToString((std::wstring(WorkingDirectory))));

	bool InDirectory = str.find(StringToWString(LowerWorkingDir)) != std::string::npos;
	if (str.find(L"\\") == std::string::npos && str.find(L":") == std::string::npos || InDirectory && str.find(L"resource.h")==std::string::npos)
	{
		if (str.find(L".cpp") != std::string::npos || str.find(L".h") != std::string::npos)
		{
			std::wstring InputFileName;
			std::wstring OutputFileName;
			if (InDirectory)
			{
				/*If we are a file such as D:\\Path\\Project\\Main.cpp
				  We need to strip Main.cpp off the end, and append it to 
				  the temp directory*/
				InputFileName = str;
				size_t IndexOfSlash = str.find_last_of(L"\\");
				if (IndexOfSlash == std::string::npos)
					return str;

				std::wstring FileDirRemoved = str.substr(IndexOfSlash + 1, str.length() - IndexOfSlash + 1);
				str.erase(IndexOfSlash + 1, str.length() - IndexOfSlash + 1);

				std::wstringstream ssTempFile;
				ssTempFile << WorkingDirectory << L"\\Temp\\" << FileDirRemoved;
				OutputFileName = ssTempFile.str();
			} else{
				/*If we are a file such as main.cpp we need to append it to the
				temp directory, and build up the input directory based on our 
				working directory (the project folder)*/
				std::wstringstream ssInFile;
				ssInFile << WorkingDirectory << L"\\" << str;
				InputFileName = ssInFile.str();

				std::wstringstream ssTempFile;
				ssTempFile << WorkingDirectory << L"\\Temp\\" << str;
				OutputFileName = ssTempFile.str();
			}
			std::wifstream InputFile;
			std::wofstream OutputFile;
			SkipNextHook = true;
			InputFile.open(InputFileName.c_str());
			OutputFile.open(OutputFileName.c_str());
			if (InputFile.is_open())
			{
				while (!InputFile.eof())
				{
					//Read Input File, Replace with Xor Contents, Write to output
					wchar_t Buffer[2048];
					InputFile.getline(Buffer, 2048);
					OutputFile << ParseXORContents(std::wstring(Buffer)) << L"\n";
				}
			}
			InputFile.close();
			OutputFile.close();
			SkipNextHook = false;
			return OutputFileName;
		}
		return str;
	}
	return str;
}
Exemplo n.º 3
0
/* extract_link_data -- given a label, parse the link data and return */
link_data * extract_link_data(char *label, scratch_pad *scratch) {
	char *temp;
	char *temp2;
	link_data *d;
	node *ref = scratch->links;
	bool debug = 0;

	if (debug)
		fprintf(stderr, "try to extract link for '%s'\n",label);
	
	if ((label == NULL) || (strlen(label) == 0))
		return NULL;
	
	temp2 = clean_string(label);
	temp = lower_string(temp2);
	
	/* look for label string as is */
	while (ref != NULL) {
		if (ref->key == KEY_COUNTER) {
			ref = ref->next;
			
			continue;
		}
		if (strcmp(ref->link_data->label, temp) == 0) {
			if (debug)
				fprintf(stderr,"a:matched %s to %s\n",ref->link_data->label, label);
			/* matched */
			d = ref->link_data;
			d = mk_link_data(d->label, d->source, d->title, d->attr);

			free(temp);
			free(temp2);
			
			return d;
		} else {
			if (debug)
				fprintf(stderr,"a:did not match %s to %s\n",ref->link_data->label, label);
		}
		ref = ref->next;
	}

	free(temp);
	free(temp2);
	
	/* No match.  Check for label()version */
	
	if (scratch->extensions & EXT_COMPATIBILITY) {
		/* not in compat mode */
		return NULL;
	}
	temp = label_from_string(label);
	
	ref = scratch->links;
	
	while (ref != NULL) {
		if (ref->key == KEY_COUNTER) {
			ref = ref->next;
			
			continue;
		}
		if (strcmp(ref->link_data->label, temp) == 0) {
			if (debug)
				fprintf(stderr,"b:matched %s to %s\n",ref->link_data->label, label);
			/* matched */
			d = ref->link_data;
			d = mk_link_data(d->label, d->source, d->title, d->attr);
			
			free(temp);

			return d;
		} else {
			if (debug)
				fprintf(stderr,"b:did not match %s to %s\n",ref->link_data->label, label);
		}
		ref = ref->next;
	}

	free(temp);
	
	if (debug)
		fprintf(stderr, "finish extract\n");
	return NULL;
}
Exemplo n.º 4
0
void main()
{
    int i,j,ch,ch2,count,tmp,vowels,consonants,y=0,x=0,k=0,n,n2,minIndex=0,maxIndex=0,max=0,min=0,l;
    char s[200],s1[200],substr[100][100]= {0},str[25][25],temp[25],*ptr;
    for(;;) {
        printf("\nEnter the choice\n");
        printf("0. Exit\n");
        printf("1. Implement library functions on a string\n");
        printf("2. Calculate string length in user defined function\n");
        printf("3. concat using user defined function\n");
        printf("4. lowercase conversion using user defined function\n");
        printf("5. uppercase conversion using user defined function\n");
        printf("6. count vowels and consonants using user defined function\n");
        printf("7. substring search using user defined function\n");
        printf("8. compare strings using user defined function\n");
        printf("9. find the largest and smallest word in a string\n");
        printf("10.check palindromic string using user defined function\n");
        printf("11.reverse a string using user defined function\n");
        printf("12.remove duplicate characters in a string using user defined function\n");
        printf("13.copy one string into another string using user defined function\n");
        printf("14.swap 2 string using user defined function\n");
        printf("15.search for a string in a user given sentence\n");
        printf("16.sort n number of words in alphabetical order\n");
        printf("17.print abbreviations of an input string\n");
        scanf("%d",&ch);
        if(ch==0) {
            printf("Terminated\n");
            break;
        }
        else {
            switch(ch) {
            case 1:
                for(;;)
                {
                    printf("0.Return to main menu\n");
                    printf("1.Length of string\n");
                    printf("2.Concate two strings\n");
                    printf("3.Convert string to lowercase\n");
                    printf("4.Convert string to uppercase\n");
                    scanf("%d",&ch2);
                    if(ch2==0)
                        break;
                    else
                    {
                        printf("Enter the String\n");
                        scanf("%s",s);
			switch(ch2)
                        {
			case 1:
                            l=strlen(s);
                            printf("String length of s = %d\n",l);
                            break;
                        case 2:
                            printf("Enter 2nd string\n");
                            scanf("%s",s1);
                            strcat(s,s1);
                            printf("Concatenated String is --> %s\n",s);
                            break;
                        case 3:
                            for(i=0; i<l; i++)
                            {
                                tmp=tolower(s[i]);
                                s[i]=tmp;
                            }
                            printf("Lowercase string = %s\n",s);
                            break;
                        case 4:
                            for(i=0; i<l; i++)
                            {
                                tmp=toupper(s[i]);
                                s[i]=tmp;
                            }
                            printf("Uppercase string = %s\n",s);
                            break;
                        default:
                            printf("Wrong Input\n");
                            break;
                        }
                    }
                }
                break;
            case 2:
                printf("Enter the string\n");
                scanf("%s",s);
                y = length(s);
                printf("Length of %s= %d\n", s, y);
                break;
            case 3:
                printf("Enter the 1st string\n");
                scanf("%s",s);
                printf("Enter the 2nd String\n");
                scanf("%s",s1);
                concat(s, s1);
                printf("The concated string is --> %s", s);
                break;
            case 4:
                printf("Enter the string\n");
                scanf("%s",s);
                lower_string(s);
                printf("String in lower case is \"%s\"\n",s);
                break;
            case 5:
                printf("Enter the string\n");
                scanf("%s",s);
                upper_string(s);
                printf("String in upper case is \"%s\"\n",s);
                break;
            case 6:
                printf("Enter a string with a tab at the end\n");
                scanf("%[^\t]",s);
                vowels=consonants=0;
                for(i=0; s[i]!='\0'; ++i)
                {
                    if(s[i]=='a' || s[i]=='e' || s[i]=='i' ||
                            s[i]=='o' || s[i]=='u' || s[i]=='A' ||
                            s[i]=='E' || s[i]=='I' || s[i]=='O' ||
                            s[i]=='U')
                        ++vowels;
                    else if((s[i]>='a'&& s[i]<='z') || (s[i]>='A'&& s[i]<='Z'))
                        ++consonants;
                }
                printf("Vowels: %d\n",vowels);
                printf("Consonants: %d\n",consonants);
                break;
            case 7:
                printf("Enter a string with a tab at the end\n");
                scanf("%[^\t]",s);
                printf("Enter the substring to search\n");
                scanf("%s",s1);
                for(i=0; s[i]!='\0'; i++)
                {
                    j=0;
                    if(s[i]==s1[j])
                    {
                        tmp=i+1;
                        while(s[i]==s1[j])
                        {
                            i++;
                            j++;
                        }
                        if(s1[j]=='\0')
                            printf("The substring is present in given string at position %d\n",tmp);
                        else
                        {
                            i=tmp;
                            tmp=0;
                        }
                    }
                }
                if(tmp==0)
                    printf("The substring is not present in given string\n");
                break;
            case 8:
                printf("Enter the 1st string\n");
                scanf("%s",s);
                printf("Enter the 2nd string\n");
                scanf("%s",s1);
                n2 = compare(s, s1);
                if (n2 == 0)
                    printf("Both are same\n");
                else if (n2 > 0)
                    printf("1st>2nd\n");
                else
                    printf("1st<2nd\n");
                break;
            case 9:
                i=0;
                k=0;
                printf("Enter a string with a tab at the end\n");
                scanf("%[^\t]",s);
                while(s[k]!='\0')
                {
                    j=0;
                    while(s[k]!=' '&&s[k]!='\0')
                    {
                        substr[i][j]=s[k];
                        k++;
                        j++;
                    }
                    substr[i][j]='\0';
                    i++;
                    if(s[k]!='\0')
                        k++;
                }
                int len=i;
                max=length(substr[0]);
                min=length(substr[0]);
                for(i=0; i<len; i++)
                {
                    y=length(substr[i]);
                    if(y>max)
                    {
                        max=y;
                        maxIndex=i;
                    }
                    if(y<min)
                    {
                        min=y;
                        minIndex=i;
                    }
                }
                printf("Largest Word is --> %s\nSmallest word is --> %s\n",substr[maxIndex],substr[minIndex]);
                break;
            case 10:
                printf("Enter the string\n");
                scanf("%s",s);
                x = palindrome(s);
                if (x == 0)
                    printf("\nNot a palindrome");
                else
                    printf("\nA palindrome");
                break;
            case 11:
                printf("Enter the string\n");
                scanf("%s",s);
                reverse(s);
                printf("The reversed string is --> %s", s);
                break;
            case 12:
                printf("Enter the string\n");
                scanf("%s",s);
                removeDuplicates(s);
                printf("String after removing duplicates: %s\n", s);
                break;
            case 13:
                printf("Enter the 1st string\n");
                scanf("%s",s);
                printf("Enter the 2nd string\n");
                scanf("%s",s1);
                copy(s, s1);
                printf("\nResultant s = %s", s);
                break;
            case 14:
                printf("Enter the 1st string\n");
                scanf("%s",s);
                printf("Enter the 2nd string\n");
                scanf("%s",s1);
                swap(s, s1);
                printf("s is %s, s1 is %s\n", s, s1);
                break;
            case 15:
                printf("press 7 please\n");
                break;
            case 16:
                printf("How many words do you want to enter?\n");
                scanf("%d",&count);
                printf("Enter the sentence\n");
                for(i=0; i<count; i++)
                    scanf("%s",str[i]);
                for(i=0; i<=count; i++)
                    for(j=i+1; j<=count; j++) {
                        if(strcmp(str[i],str[j])>0) {
                            strcpy(temp,str[i]);
                            strcpy(str[i],str[j]);
                            strcpy(str[j],temp);
                        }
                    }
                printf("The sentence sorted alphabetically is --> ");
                for(i=0; i<=count; i++)
                    printf("%s ",str[i]);
                break;
            case 17:
                printf("Enter a string with a tab at the end\n");
                scanf("%[^\t]",s);
                l=strlen(s);
                ptr=s;
                printf("%c",*(ptr+1));
                for(i=1; i<l; i++)
                {
                    if(*(ptr+i-1)==' ')
                        printf("%c",*(ptr+i));
                }
                break;
            default:
                printf("Invalid choice");
                break;
            }
        }
    }
}
Exemplo n.º 5
0
Arquivo: cfg.c Projeto: Benocs/pmacct
/* parse_plugin_names() leaves cfg array untouched: parses the key 'plugins'
   if it exists and creates the plugins linked list */ 
int parse_plugin_names(char *filename, int rows, int ignore_names)
{
  int index = 0, num = 0, found = 0;
  char *start, *end, *start_name, *end_name;
  char key[SRVBUFLEN], value[10240], token[SRVBUFLEN], name[SRVBUFLEN];

  /* searching for 'plugins' key */
  while (index < rows) {
    memset(key, 0, SRVBUFLEN);
    start = NULL; end = NULL;

    start = cfg[index];
    end = strchr(cfg[index], ':');
    if (end > start) {
      strlcpy(key, cfg[index], (end-start)+1); 
      if (!strncmp(key, "plugins", sizeof("plugins"))) {
	start = end+1;
	strcpy(value, start); 
	found = TRUE;
	break;
      }
    }
    index++;
  }

  if (!found) return 0;

  /* parsing declared plugins */
  start = value;
  while (*end != '\0') {
    memset(token, 0, SRVBUFLEN);
    if (!(end = strchr(start, ','))) end = strchr(start, '\0');
    if (end > start) {
      strlcpy(token, start, (end-start)+1);
      if ((start_name = strchr(token, '[')) && (end_name = strchr(token, ']'))) {
        if (end_name > (start_name+1)) {
          strlcpy(name, (start_name+1), (end_name-start_name));
	  trim_spaces(name);
	  *start_name = '\0';
	}
      }
      else strcpy(name, "default");
	
      /* Having already plugins name and type, we'll filter out reserved symbols */
      trim_spaces(token);
      lower_string(token);
      if (!strcmp(token, "core")) {
        Log(LOG_ERR, "ERROR ( %s ): plugins of type 'core' are not allowed. Exiting.\n", filename);
        exit(1);
      }
      if (!ignore_names) {
        if (create_plugin(filename, name, token)) num++;
      }
      else {
        if (create_plugin(filename, "default", token)) num++;
      }
    }
    start = end+1;
  }

  /* having already processed it, we erase 'plugins' line */
  memset(cfg[index], 0, strlen(cfg[index]));

  return num;
}
Exemplo n.º 6
0
void init_desc_array(void)
{
	int c, l;

	DESC* desc = (DESC*) calloc(1, sizeof(*desc));

	FILE* f = NULL;
	FILE* f_desc = NULL;
	
	char desc_filename[256];
	char buffer[256];
	char* filename = "descs/desc.all";
	
	char* plugin_filename = (char* ) calloc(80, sizeof(*plugin_filename));

	DEBUG_MSG("Init desc files parsing");

	f = fopen(filename, "r");
	if (!f)
		exit(EXIT_FAILURE);

	l = get_file_lines_count(f);

	DEBUG_MSG("%d files in list", l);

	/* allocate memory */
	DESC_ARRAY_LENGTH = l;
	DESC_ARRAY = calloc(DESC_ARRAY_LENGTH, sizeof(DESC));

	fseek(f, 0, 0);

	/* parse files */
	c = 0;
	while (fgets(buffer, sizeof(buffer), f) != 0) {
	
		sscanf(buffer, "%s", buffer);
		strcpy(desc_filename, "descs/");
		strcat(desc_filename, buffer);

		if (is_desc_file(desc_filename)) {

			f_desc = open_file(desc_filename);

			if (f_desc) {
				if (parse_desc_file(f_desc, desc) == PARSE_SUCCESS) {

					DEBUG_MSG("%s parsing succeeds", desc_filename);

					sprintf(plugin_filename, "descs/%s.so", desc->name);
			
					lower_string(plugin_filename);

					/* load .so */
					if (load_desc_so(plugin_filename, desc)) {
						DEBUG_MSG("%s loaded", plugin_filename);
					}

					DESC_ARRAY[c] = *desc;

				} 
				else {
					WARNING_MSG("parsing fails for %s", desc_filename);
				}
				close_file(f_desc);
				c++;
			}
		}
	}

	fclose(f);

	/* free the mallocs */
	free(plugin_filename);
	free(desc);

	DEBUG_MSG("End desc files parsing");
}
Exemplo n.º 7
0
std::string get_lower_string(const std::string &str)
{
    std::string ret(str);
    lower_string(ret);
    return ret;
}