Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First of all, hello to everyone. I want to solve a problem using C language. But I'm just learning C. My problem is as follows. I need to solve this problem without using an array. Waiting for help.

EXAMPLE

file.txt before any operation :
12 -5      67            12   4         -888   23  5  7  67 2
56       3              67           6        5
45            -5              3           12  7   1 


Your program finds the repeated integers and replaces their position with empty space.

file.txt after the execution:
12 -5      67                 4         -888   23  5  7     2
56       3                           6         
45                                                1 


What I have tried:

printf("Enter the filename to open \n"); 
scanf("%s", filename); 
printf("Text now\n");

// Open file 
fptr = fopen(filename, "r"); 

// Read contents from file 
c = fgetc(fptr); 
while (c != EOF) 
{ 
    printf ("%cX", c); 
    c = fgetc(fptr); 
} 

printf("Lutfen ayni degerli elemanlari silmek icin 1'e basiniz.\n");
scanf("%d", &delete);

while (delete != 1){
    printf("Lutfen 1'e basiniz.\n");
     scanf("%d", &delete);
}

for(i = 1; i <= EOF; i = i + 1)
    if (c == c+i)
        c+i = c;
Posted
Updated 5-Oct-19 23:34pm
Comments
KarstenK 6-Oct-19 13:23pm    
tip: use only language in your project. Best is englisch.

1 solution

If your tutor has said you can't use any arrays, then you will have to do one of two things:
1) Set up a linked list (using pointers) to hold each integer value.
2) Pass through the input file multiple times, checking and removing each duplicate one per pass.

The first option is the most efficient, but requires knowledge of how to allocate memory, structs, and how use pointers.

I would strongly suggest you re-read your homework and check exactly what it expects you do to, and check that against your last lesson content - it should be relevant to the task you have been set.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900