-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuseful.h
More file actions
54 lines (40 loc) · 1.03 KB
/
useful.h
File metadata and controls
54 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef _useful_
#define _useful_
#include<stdlib.h>
#include<ctype.h>
//Função para retornar posição de caracter na string
int pos(char* string, char search, int occurrence){
if (occurrence < 1)
return -1;
int _occurrence = 0;
int i=0;
for(i=0; i<strlen(string); i++)
{
if(string[i] == search){
_occurrence++;
if(occurrence == _occurrence)
return i;
}
}
return -1;
}
//Função para encontrar parte da string
void substring(char* result, char* string, int start, int length){
int i;
int max = length+start;
if (max > strlen(string))
max = strlen(string);
for(i=start; i<max; i++)
result[i-start] = string[i];
result[max-start] = '\0';
}
//Função para retirar caracteres em branco na string
char* trim (char *s)
{
int i;
while (isspace (*s)) s++; // skip left side white spaces
for (i = strlen(s)-1; (isspace(s[i]) && i>0); i--) ; // skip right side white spaces
s[i+1] = '\0';
return s;
}
#endif