How to convert a specific row of a matrix to a string in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

void convert_int_array_to_string(int arr[], int size, char str[]) {
    for (int i = 0; i < size; i++) {
        sprintf(str + strlen(str), "%d ", arr[i]);
    }
}
  
int main() {
    int arr[] = { 4, 7, 5, 18, 29, 0, 3 };
    char str[128];
    
    int size = sizeof(arr) / sizeof(arr[0]);
  
    convert_int_array_to_string(arr, size, str);
      
    puts(str);
  
    return 0;
}
  
  
  
/*
run:
  
4 7 5 18 29 0 3 
  
*/

 



answered Jul 9, 2024 by avibootz
edited Jul 10, 2024 by avibootz

Related questions

...