Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void espace(char* ch,int n,int* res,char** adrch2){
- int i,nbEspaces = 1,bInf,bSup;
- char *ch2;
- for(i=0;i<strlen(ch);i++){
- if (nbEspaces == n){
- bSup = i;
- }
- if (ch[i] == ' '){
- nbEspaces++ ;
- }
- }
- i=bSup;
- while(i>0){
- i--;
- if (ch[i] == ' '){
- bInf = i;
- break;
- }
- }
- *res = nbEspaces <= n;
- ch2 = (char*) malloc((bSup-bInf+2)*sizeof(char));
- for (i=bInf;i<=strlen(ch);i++){
- ch2[i-bInf]=ch[i];
- }
- *adrch2 = ch2;
- }
- int main(){
- char ch[20] ;
- int n,res;
- int *pres = &res;
- char *ch2 = NULL;
- gets(ch);
- printf("\n donner n: ");
- scanf("%d",&n);
- espace(ch,n,pres,&ch2);
- res = *pres;
- printf("\nch2: %s; res: %d",ch2,res);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement