Read a string char by char from an associative pointer array

Read a string char by char from an associative pointer array

I hope the title of my question is correct.

I hope the title of my question is correct.

I have a stringpool

char **string_pool;

that gets initiated in a function like

string_pool = malloc( sizeof(char *) * 1024);

i get strings from stdin and scanf them into the array

scanf("%[^\n]s", &string_pool[index]);

so i can print it out using printf

printf("gets %s\n", &string_pool[index]);

how can i

  • get the length of string_pool[index]
  • read string_pool[index] char by char in a loop

Thank you

Edit

Maybe i should explain it a bit more, its a virtual machine with a virtual instruction set and a program like

push 1
read
gets

should :

  • push 1 on the stack -> let x be 1
  • read stdin as string into string_pool[x]
  • push all characters onto the stack

the functions looks like

    case GETS: {
        int index = popv(); // index is already on top of the stack
        int strl = strlen(&string_pool[index]);

    printf("gets %s with a length of %d\n", &string_pool[index], strl);
    // pseudo code
    // push each char as integer on the stack
    foreach(char in string_pool[index]) push((int)char);

    break;
}

case READ: {  
    int index = popv();          
    scanf("%[^\n]s", &string_pool[index]);
    break;
}

case WRITE: {  
    int index = popv();          
    printf("%s", &string_pool[index]);
    break;
}

My problem is in the GETS case. I want to push every char as int onto the stack.

c arrays string

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

C++ Arrays And Multidimensional Arrays

In this article we are going to talk about C++ Arrays And Multidimensional Arrays, so c++ arrays are collection of the elements that are the same type.

C++ Arrays And Multidimensional Arrays

In this video we are going to talk about C++ Arrays And Multidimensional Arrays, so c++ arrays are collection of the elements that are the same type.

Anonymous array in C#| Anonymous Collection | C# Bangla Tutorial | Advanced C#

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorial, I will discussed about Anonymous Array in C#. Blog : http://aspdotnetexplorer.blogspot.com Like our page...

Learn C ++ From Scratch (2 Strings, Vectors, and Arrays)

It can be said that string and vector are the two most important types in the C++ standard library. String supports variable-length strings, and vector represents a variable-length collection.

Count of triplets (a, b, c) in the Array such that a divides b and b divides c

A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.