//Youtube: https://[Log in to view URL]
//myCompiler https://[Log in to view URL]
#include <stdio.h>
#include <string.h>
int main() {
// Example input string
char input[] = "BTCabcdefghij .085 114532.65";
//char input[] = "BTC .085 114532.65";
char ticker_full[99+1]; // large buffer to hold any ticker
char ticker[9 + 1]; // safe buffer: 9 chars + null terminator
double amount;
double price;
// First parse everything (ticker_full may be longer than 9 chars)
int matched = sscanf(input, "%99s %lf %lf", ticker_full, &amount, &price);
if (matched == 3) {
// Copy only up to 9 chars safely
strncpy(ticker, ticker_full, 9);
ticker[9] = '\0'; // ensure null termination
// Warn if truncation happened
if (strlen(ticker_full) > 9) {
printf("%s Warning: Ticker '%s' truncated to '%s'\n",
"⚠",ticker_full, ticker);
}
double total_value = amount * price;
printf("Crypto Ticker : %s\n", ticker);
printf("Amount Owned : %.8f\n", amount);
printf("Price (USD) : $%.2f\n", price);
printf("Total Value : $%.2f\n", total_value);
} else {
printf("Parsing error! Only %d values matched.\n", matched);
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: