Search
 
SCRIPT & CODE EXAMPLE
 

C

find a substring within a string in c and return the index

int findocc(const char* s1, unsigned int n){
    int i =0;
    int j = n;
    // find the size of the number
    while(n > 0){n /=10 ; i++;}

    char buff[i];
    sprintf(buff, "%d", j);

    // Find the first apperance of n in s1;
    char * found = strstr(s1, buff);

    if(!found){
        return 0;
    }

//    int s=0;
//    for (const char *ptr=s1;  *ptr;  ptr++) {
//        if(strncmp(ptr, buff,i) == 0){
//            return s;
//        }else{
//            s++;
//        }
//    }

    return found - s1;
}
Comment

PREVIOUS NEXT
Code Example
C :: command line coursera 
C :: bash sed crop cut file line number 
C :: deepak rake 
C :: tetris rotate shape 
C :: maximum, minimum, mean, and median of the data set. in array c programming 
C :: write a ppm image 
C :: passage on dowry 
C :: C program to Increase 1 to all of the given Integer Digit 
C :: #include <stdio.h int main() { int x = 10, *y, **z; y = &x; z = &y; printf(""%d %d %d"", *y, **z, *(*z)); return 0; } 
C :: /usr/bin/mandb: fopen /var/cache/man/7935: Permission denied 
C :: is 0 true or false 
C :: bit wise operation 
C :: Word Processor, Spreadsheet and Presentation Software are the examples of 
C :: what is float in c 
C :: how to write a hello world program in c 
C :: mark rober 
C :: how can i show ant text by onclick 
Dart :: flutter wait for specific time 
Dart :: remove appbar shadow flutter 
Dart :: flutter random pick in list 
Dart :: hide keyboard flutter 
Dart :: how to get sha key in flutter 
Dart :: borderradius.only flutter 
Dart :: flutter delete chip 
Dart :: flutter listtile color 
Dart :: flutter AnimatedOpacity 
Dart :: dartpad missing browser features 
Dart :: throw error in dart 
Dart :: math.round dart 
Dart :: sort list bool dart 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =