Difference between writeValue data as NSData in Objective C and Data in Swift

I'm writing to a CoreBluetooth device using

I'm writing to a CoreBluetooth device using

- (void)writeValue:(NSData *)data forCharacteristic:(CBCharacteristic *)characteristic type:(CBCharacteristicWriteType)type;

in objective C

I would like to move this code over to Swift. Therefore I'm writing using

 open func writeValue(_ data: Data, for characteristic: CBCharacteristic, type: CBCharacteristicWriteType)

All of the parameter values being sent are the same except data when sent as NSData will be represented as such <000a0302>. In Swift the data is represented as

▿ 4 bytes - count : 4 ▿ pointer : 0x00000002810ce5b0 - pointerValue : 10755040688 ▿ bytes : 4 elements - 0 : 0 - 1 : 10 - 2 : 3
  • 3 : 2

However I am not getting the same result back from the bluetooth peripheral - what is the difference between the two examples?

How to populate an array with another variable in Obj-C

Following the discussion on string interpolation on Obj-C (<a href="https://stackoverflow.com/questions/54300658/objective-c-equivalent-of-swift-variable/54300867?noredirect=1#comment95454640_54300867" target="_blank">Objective-C equivalent of Swift "\(variable)"</a>), I am looking at the way to do something like the following in Obj-C. Thanks!

Following the discussion on string interpolation on Obj-C (Objective-C equivalent of Swift "\(variable)"), I am looking at the way to do something like the following in Obj-C. Thanks!

let hotel = "Hilton"
var roomNumberArray = ["\(hotel)01", "\(hotel)02", "\(hotel)03", "\(hotel)04", "\(hotel)05", "\(hotel)06", "\(hotel)07", "\(hotel)08", "\(hotel)09", "\(hotel)10"]


Increased array size. after increaseSize function some arguments of the same array are invalid. C lang

The program takes some txt input from "numbers.txt" file. It first counts the&nbsp;<strong><em>amount</em></strong>&nbsp;of all the numbers (freqCount)in that text file, than reads the file again and with the use of malloc it creates two arrays A and B , of which both have size equal to the&nbsp;<strong>amount</strong>&nbsp;of all the numbers in the text file. So far so good.

The program takes some txt input from "numbers.txt" file. It first counts the amount of all the numbers (freqCount)in that text file, than reads the file again and with the use of malloc it creates two arrays A and B , of which both have size equal to the amount of all the numbers in the text file. So far so good.

Now i want to increase the size of the array A, so that I can put "freqCount" more arguments in it. In the freqRepeat function I created, there is a function increaseSize which takes that same array A, and uses realloc to add 2*freqCount more arguments in it.

After calling the mentioned function increaseSize there is a problem, because only part of the arguments remain unchanged, and there are few arguments that become some huge number. This is a major issue. Can anyone please provide me with some help ? thanks

ps. I include the expemplary text file input at the end of the code.

#include <stdio.h>
#include <stdlib.h>
int read_ints(const char *file_name, int *result);
int *scanFreq(const char *file_name, int *A, int *B, int *resultTab);
int freqRepeat(int *A, int *B, int freqCount);
int *increaseSize(int *A, int freqCount);
void calcmalc(int freqCount);
int *nextArray(int *A, int *B, int freqCount, int freqStart);

int main()
{
int result = 0;
int resultTab = 0;
int freqCount;
freqCount = read_ints("numbers.txt", &result);
printf("freqCount is %d", freqCount);
int *A = (int *)malloc(freqCount * sizeof(int));
int *B = (int *)malloc(freqCount * sizeof(int));
scanFreq("numbers.txt", A, B, &resultTab);
freqRepeat(A, B, freqCount);

}
int read_ints(const char *file_name, int *result)
{
FILE *file = fopen("numbers.txt", "r");
int i = 0;
int n = 0; //row number//

if (file == NULL)
{
printf("unable to open file %s", file_name);
}

while (fscanf(file, "%d", &i) == 1)
{
n++;
printf("%d\n ", i);
*result += i;
printf("\n we are at row nr. %d sum of this number and all numbers before is: %d\n", n, *result);
}
fclose(file);
return n;
}
int *scanFreq(const char *file_name, int *A, int *B, int *resultTab)
{
FILE *file = fopen("numbers.txt", "r");
int i = 0;
int n = 0; //row number//

if (file == NULL)
{
printf("unable to open file %s", file_name);
}

while (fscanf(file, "%d", &i) == 1)
{
n++;
*resultTab += i;
B[n] = i;
A[n] = *resultTab;
}
fclose(file);
return 0;
}

int freqRepeat(int *A, int *B, int freqCount)
{
int lastFrequency;

lastFrequency = freqCount;
freqCount = freqCount + freqCount;
A = increaseSize(A, freqCount);

printf("\n\nwcis enter\n\n");
getchar();

for (int i = 1; i < 15; i++)
{
printf("array argument after increasing array size %d \n", A[i]);

// why some of the arguments have been changed ????????
}

return 0;
}
int *increaseSize(int *A, int freqCount)
{

return realloc(A, 2 * sizeof(int));
}

text input:
-14
+15
+9
+19
+18
+14
+14
-18
+15
+4
-18
-20
-2
+17
+16
-7
-3
+5
+1
-5
-11
-1
-6
-20
+1
+1
+4
+18
+5
-20
-10
+18
+5
-4
-5
-18
+9
+6
+1
-19
+13
+10
-22
-11
-14
-17
-10
-1
-13
+6
-17