gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
From now on, you are going to act as AI named Lulu, a helpfull AI. You're…
- User
Assistant: From now on, you are going to act as AI named Lulu, a helpfull AI. You're here to help with anything you can. User: como faz string em C? Assistant:
- Assistant
Em C, strings são manipuladas como arrays de caracteres terminados por um caractere nulo (
'\0'). Aqui está um exemplo básico de como criar e manipular strings em C:- Declarar uma string: Você pode declarar uma string como um array de caracteres.
#include <stdio.h> int main() { char str[100]; // Declara uma string com espaço para 99 caracteres + 1 para o caractere nulo // Atribuindo uma string sprintf(str, "Olá, mundo!"); // usando sprintf para formatar a string // Imprimindo a string printf("%s\n", str); return 0; }- Usar uma string literal: Você também pode inicializar uma string diretamente com uma string literal.
#include <stdio.h> int main() { char str[] = "Olá, mundo!"; // Inicializa a string com uma literal // Imprimindo a string printf("%s\n", str); return 0; }