Jump to content
Fórum Script Brasil
  • 0

Ler Matriz dentro de arquivo


Cas.Felippe

Question

2 answers to this question

Recommended Posts

  • 0

Obrigado pela dica, mas acabei fazendo pela função fscan()

Precisei alterar o programa que fazia a matriz acrescentando um espaço aqui o código:

#include<stdio.h>
#include<stdlib.h>

int main()
{
    int matriz[3][3];
    int i,j;
    int a,b;

    FILE *fp;
    
    fp= fopen("i3x3.txt","r");
    while(!feof(fp))
    {
        for(i=0;i<3;i++)
        {
            for(j=0;j<3;j++)
            {
                fscanf(fp,"%d",&matriz[i][j]);
            }
        }
    }

    printf("Matriz lida com sucesso\n");

    for(a=0;a<3;a++)
    {
        for(b=0;b<3;b++)
        {
            printf("%d",matriz[a][b]);
        }
        printf("\n");
    }

    fclose(fp);
    return 0;
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...