September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
52
Task/Substring/C/substring-1.c
Normal file
52
Task/Substring/C/substring-1.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* RosettaCode: Substring, C89
|
||||
*
|
||||
* In this task display a substring: starting from n characters in and of m
|
||||
* length; starting from n characters in, up to the end of the string; whole
|
||||
* string minus last character; starting from a known character within the
|
||||
* string and of m length; starting from a known substring within the string
|
||||
* and of m length.
|
||||
*
|
||||
* This example program DOES NOT make substrings. The program simply displays
|
||||
* certain parts of the input string.
|
||||
*
|
||||
*/
|
||||
#define _CRT_SECURE_NO_WARNINGS /* MSVS compilers need this */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Put no more than m characters from string to standard output.
|
||||
*
|
||||
* It is worth noting that printf("%*s",width,string) does not limit the number
|
||||
* of characters to be printed.
|
||||
*
|
||||
* @param string null terminated string
|
||||
* @param m number of characters to display
|
||||
*/
|
||||
void putm(char* string, size_t m)
|
||||
{
|
||||
while(*string && m--)
|
||||
putchar(*string++);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
char string[] =
|
||||
"Programs for other encodings (such as 8-bit ASCII, or EUC-JP)."
|
||||
|
||||
int n = 3;
|
||||
int m = 4;
|
||||
char knownCharacter = '(';
|
||||
char knownSubstring[] = "encodings";
|
||||
|
||||
putm(string+n-1, m ); putchar('\n');
|
||||
puts(string+n+1); putchar('\n');
|
||||
putm(string, strlen(string)-1); putchar('\n');
|
||||
putm(strchr(string, knownCharacter), m ); putchar('\n');
|
||||
putm(strstr(string, knownSubstring), m ); putchar('\n');
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
56
Task/Substring/C/substring-2.c
Normal file
56
Task/Substring/C/substring-2.c
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* RosettaCode: Substring, C89, Unicode
|
||||
*
|
||||
* In this task display a substring: starting from n characters in and of m
|
||||
* length; starting from n characters in, up to the end of the string; whole
|
||||
* string minus last character; starting from a known character within the
|
||||
* string and of m length; starting from a known substring within the string
|
||||
* and of m length.
|
||||
*
|
||||
* This example program DOES NOT make substrings. The program simply displays
|
||||
* certain parts of the input string.
|
||||
*
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Put all characters from string to standard output AND write newline.
|
||||
* BTW, _putws may not be avaliable.
|
||||
*/
|
||||
void put(wchar_t* string)
|
||||
{
|
||||
while(*string)
|
||||
putwchar(*string++);
|
||||
putwchar(L'\n');
|
||||
}
|
||||
|
||||
/*
|
||||
* Put no more than m characters from string to standard output AND newline.
|
||||
*/
|
||||
void putm(wchar_t* string, size_t m)
|
||||
{
|
||||
while(*string && m--)
|
||||
putwchar(*string++);
|
||||
putwchar(L'\n');
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
wchar_t string[] =
|
||||
L"Programs for other encodings (such as 8-bit ASCII).";
|
||||
|
||||
int n = 3;
|
||||
int m = 4;
|
||||
wchar_t knownCharacter = L'(';
|
||||
wchar_t knownSubstring[] = L"encodings";
|
||||
|
||||
putm(string+n-1,m);
|
||||
put (string+n+1);
|
||||
putm(string, wcslen(string)-1);
|
||||
putm(wcschr(string, knownCharacter), m );
|
||||
putm(wcsstr(string, knownSubstring), m );
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue