C Tutorial/Wide Character String/Wide Character String Search — различия между версиями


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 10:32, 25 мая 2010

Find occurrences of one wide character string in another wide character string

#include <stdio.h>
#include <wchar.h>
int main(void)
{
  wchar_t text[100];
  wchar_t substring[40];
  printf("\nEnter the string to be searched(less than 100 characters):\n");
  fgetws(text, 100, stdin);
  printf("\nEnter the string sought (less than 40 characters ):\n");
  fgetws(substring, 40, stdin);
  text[wcslen(text)-1] = L"\0";
  substring[wcslen(substring)-1] = L"\0";
  printf("\nFirst string entered:\n%S\n", text);
  printf("\nSecond string entered:\n%S\n", substring);
  int i;
  for(i = 0 ; (text[i] = towupper(text[i])) ; i++);
  for(i = 0 ; (substring[i] = towupper(substring[i])) ; i++);
  printf("\nThe second string %s found in the first.",((wcsstr(text, substring) == NULL) ? "was not" : "was"));
  return 0;
}
Enter the string to be searched(less than 100 characters):
asdfasdfasdfasdfasdf
Enter the string sought (less than 40 characters ):
as
First string entered:
asdfasdfasdfasdfasdf
Second string entered:
as
The second string was found in the first.