How to write a C Program to Returns: array of decoded values. [0] - count of values in C Programming Language ?
Solution:
#include <stdlib.h>
#include <string.h>
/* Returns: array of decoded values. [0] - count of values */
int *decode(char *encoded) {
int idx = 1;
int maxlen = 8;
char *token;
char *delim = " :;,|";
int *nums = malloc(maxlen * sizeof(int));
/* Preserve the original string */
encoded = strdup(encoded);
token = strtok(encoded, delim);
nums[1] = atoi(token);
while (token = strtok(NULL, delim)) {
if (idx >= maxlen) {
maxlen += 8;
nums = realloc(nums, maxlen * sizeof(int));
}
nums[++idx] = atoi(token);
}
nums[0] = idx;
return nums;
}
Learn More :
Count
- C Program String - Alphabet Count Example
- C Program String Count Example
- Write the procedure , which is one of a sum , a product and a geometric average in the panel for the NxM elements are located on opposite diagonal and main diagonal . Remind ! Counting only odd elements !
- C Program Array NxM Elements Geometric/Arithmetic
- C Program to Count Number of Lines in Input until Interrupted by CTRL + Z
- Max count of chars, Max count of nums and Max count of signs
- C Program to Count Vowels, Consonants and Spaces in a string
- C Program to count number of sentences words and letters in a paragraph
- Un-sortiertes Array and Sortiertes Array
- C Program to Count Change Program
- LED ON OFF For One Sec/Count and Display on the Attached Serial Monitor
- Menu driven program in C which performs the following operations on strings
- C program to accept n number from user,store these numbers into an array & count the no of occurrences of each number
Return
Array
- How to pass one dimensional array to function in c.
- Write a c program which passes two dimension array to function.
- C Program Array Index Example
- C Program Array Example: Average
- C Program Array Example: Reverse
- C Program Array Example
- C Program to Array
- C Program Array NxM Elements Geometric/Arithmetic
- C Program To Find The Maximum And Minimum Value In An Array
- C Program To Find Union & Intersection Of Two Array
- C Program To Search A Number Inside The Array
- C Program To Sort An Array In Ascending And Descending Order
- C Program To Sort An Array Of Names In Alphabetical And Reverse Order
- C Program To Copy One Character Array Into Another
- C Program to Check if a number is in an array[1000]
- C Program to Find max and min in array using pointer concept
- C Program Sort Array By Segment
- C Program to sort an array using bubble sort
- C Program to find smallest in an array using pointer
- C Program to merge and sort two arrays
- Un-sortiertes Array and Sortiertes Array
- C Program to Array Deserialization
- C program calculates a given function in range given by user, stores the data in arrays and displays the answer in a table.
- Input reads in the array positions and range for random generation.